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
mkleifgen
Frequent Visitor

Rolling 12. Mo. in a matrix, for EVERY Month

Hello,

 

I need to create a matrix with Month and Year as the columns, and a distinctcount of customer numbers as the value.

The problem is the distinct count of customer numbers needs to be 12 mo. rolling behind every month.

 

January 2017 column needs to return distinctcount of customer numbers from February 2016 - January 2017.

March 2018 column needs to return distinctcount of customer numbers from April 2017 - March 2018.

 

I have a sales data table with customer number, and document date columns.

If you need more information for how anything is set up please let me know.

This can't be as complicated as it seems, I must be missing something.

 

Thanks!

 

-Mark

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @mkleifgen,

 

Please refer to below DAX formulas. Remember to change the data type of [YearMonth] to whole number.

YearMonth = FORMAT('Data Table'[Date],"YYYYMM")

Rank =RANKX ( 'Data Table', 'Data Table'[YearMonth],, ASC, DENSE )

Rolling count =
CALCULATE (
    DISTINCTCOUNT ( 'Data Table'[Customer] ),
    FILTER (
        'Data Table',
        'Data Table'[Rank] <= EARLIER ( 'Data Table'[Rank] )
            && 'Data Table'[Rank]
                >= EARLIER ( 'Data Table'[Rank] ) - 4
    )
)

1.PNG2.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

3 REPLIES 3
v-yulgu-msft
Employee
Employee

Hi @mkleifgen,

 

Please refer to below DAX formulas. Remember to change the data type of [YearMonth] to whole number.

YearMonth = FORMAT('Data Table'[Date],"YYYYMM")

Rank =RANKX ( 'Data Table', 'Data Table'[YearMonth],, ASC, DENSE )

Rolling count =
CALCULATE (
    DISTINCTCOUNT ( 'Data Table'[Customer] ),
    FILTER (
        'Data Table',
        'Data Table'[Rank] <= EARLIER ( 'Data Table'[Rank] )
            && 'Data Table'[Rank]
                >= EARLIER ( 'Data Table'[Rank] ) - 4
    )
)

1.PNG2.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

For future users,

 

In order to continue to grab the rolling count of customers carrying unique items...

I added 

Rolling count =
CALCULATE (
    DISTINCTCOUNT ( 'Data Table'[Customer] ),
    FILTER (
        'Data Table',
        'Data Table'[Rank] <= EARLIER ( 'Data Table'[Rank] )
            && 'Data Table'[Rank]
                >= EARLIER ( 'Data Table'[Rank] ) - 4
    )
'Data Table'[Item Number] = EARLIER('Data Table'[Item Number]) )

Thank you so much for your help @v-yulgu-msft!

This has helped a ton and taught me a lot!

-Mark

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.