Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Rolling sum count of number of entries for 4 quarters based on year selection

Hello All,

 

I got a table called "OverallData" which contains entries for past 5 years. Table structure is as follows

 

NameDateStatusProgram Name
ABC1/10/2015Started2-7 Months
XYZ5/14/2016Closed4-12 Months programs
AAA2/22/2018In ProgressEmployee Engagement
AN8/16/2019In ProgressExecutive program
MYX9/20/2022 Retirement program

 

I want to create a table with Program Name as Row headers and Status as column headers. But I want to showcase rolling sum when I select the quarter year slicer i.e. On selecting Q4 2022 from slicer it should showcase me the values till start of Q4 2021 and so on. I do have a separate date table "dimDate" which contain dates from 2015 till date. Can someone help me with appropriate DAX for this scenario as the below one doesn't seem to giving me the correct output.

 

 

rollSum = CALCULATE(COUNT(OverallData[Status]),DATEADD(dimDate[Date],-4,QUARTER))

 

 

1 ACCEPTED SOLUTION
v-yinliw-msft
Community Support
Community Support

Hi @Anonymous ,

 

 I do have a separate date table "dimDate" which contain dates from 2015 till date. 

For your case, we just need a Quarter- Year Column  and an additional column for sorting like:

Quarter Slicer = 
var _q={"Q1","Q2","Q3","Q4"}
var _y=VALUES(OverallData[Date].[Year])
return  SELECTCOLUMNS(CROSSJOIN(_q,_y) ,"Qua - Year", [Value] & " "&[Date].[Year], "Index", [Date].[Year]*100+RIGHT([Value],1))

Eyelyn9_0-1667568547333.png

 

Then please create a measure :

rollSum =
CALCULATE (
    COUNT ( OverallData[Status] ),
    FILTER (
        'OverallData',
        YEAR ( [Date] ) * 100
            + QUARTER ( [Date] )
            >= SELECTEDVALUE ( 'Quarter Slicer'[Index] ) - 100
            && YEAR ( [Date] ) * 100
                + QUARTER ( [Date] )
                <= SELECTEDVALUE ( 'Quarter Slicer'[Index] )
    )
)

Output:

Eyelyn9_1-1667568643373.png

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yinliw-msft
Community Support
Community Support

Hi @Anonymous ,

 

 I do have a separate date table "dimDate" which contain dates from 2015 till date. 

For your case, we just need a Quarter- Year Column  and an additional column for sorting like:

Quarter Slicer = 
var _q={"Q1","Q2","Q3","Q4"}
var _y=VALUES(OverallData[Date].[Year])
return  SELECTCOLUMNS(CROSSJOIN(_q,_y) ,"Qua - Year", [Value] & " "&[Date].[Year], "Index", [Date].[Year]*100+RIGHT([Value],1))

Eyelyn9_0-1667568547333.png

 

Then please create a measure :

rollSum =
CALCULATE (
    COUNT ( OverallData[Status] ),
    FILTER (
        'OverallData',
        YEAR ( [Date] ) * 100
            + QUARTER ( [Date] )
            >= SELECTEDVALUE ( 'Quarter Slicer'[Index] ) - 100
            && YEAR ( [Date] ) * 100
                + QUARTER ( [Date] )
                <= SELECTEDVALUE ( 'Quarter Slicer'[Index] )
    )
)

Output:

Eyelyn9_1-1667568643373.png

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.