Search code examples
powerbidax

group by and sum in DAX based on the fiscal week


I have a data as below and I would like to create a powerbi card to show the current Fiscal week and the previous fiscal week value. many thanks in advance.

Expected Answer :

Current Amt: 20
Previous Amt: 35

Current input :

FiscalWeek  Group   Amt FiscalYear
52          gorup1  10  FY23
52          gorup2  20  FY24
51          gorup1  30  FY24
51          gorup2  5   FY24
50          gorup1  10  FY24
50          gorup2  15  FY24

Solution

  • You need 2 measures for current and previous :

    Current Amt = 
    VAR CurrentFiscalWeek = MAX('TableTest'[FiscalWeek])
    RETURN
    CALCULATE(
        SUM('TableTest'[Amt]),
        'TableTest'[FiscalWeek] = CurrentFiscalWeek
    )
    
    Previous Amt = 
    VAR CurrentFiscalWeek = MAX('TableTest'[FiscalWeek])
    VAR PreviousFiscalWeek = CurrentFiscalWeek - 1
    RETURN
    CALCULATE(
        SUM('TableTest'[Amt]),
        'TableTest'[FiscalWeek] = PreviousFiscalWeek
    )
    

    You can use the new card visual :

    enter image description here

    enter image description here

    enter image description here