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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
itsmebvk
Continued Contributor
Continued Contributor

How to create Rolling 6 month with YYYYM column ?

Hi Folks, I need some help in crating DAX for rolling 6 months without date column.

 

My fiscal year starts on 1st Sunday of every August, I dont have date column in the tables but I have YYYYP column available in the both Date and Category table. Using YYYYP can we create Rolling 6 months measure?

 

Note: I tried to use DATEYTD, TOTALYTD but I am unable to get desired output as my Fiscal year start date is not constant in starts on 1st Sunday of every August.

 

CAn you please suggest anywork around to get rolling 6 months data?

 

Thanks in adavance.

 

Fiscal YearFiscal MonthYYYYMRevenue
2020120201100
2020220202200
2020320203300
2020420204400
2020520205500
2020620206600
2020720207700
2020820208800
2020920209900
202010202101000
202011202111100
202012202121200
202013202131300
20211202111400
20212202121500
20213202131600
20214202141700
20215202151800

 

Category Table

 

CategoryRevenueFiscalFiscal MonthYYYYM
A120020201220212
A130020201320213
A14002021120211
A15002021220212
A16002021320213
A17002021420214
A18002021520215
B100020201220212
B110020201320213
B12002021120211
B17002021220212
B18002021320213
B`14002021420214
B20002021520215
1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @itsmebvk 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

Category:

b2.png

 

You may create measures as below.

6 months roll total = 
CALCULATE(
    SUM('Table'[Revenue]),
    FILTER(
        ALL('Table'),
        'Table'[YearMonth] in 
        TOPN(
            6,
            CALCULATETABLE(
                DISTINCT('Table'[YearMonth]),
                FILTER(
                   ALL('Table'),
                   'Table'[YearMonth]<=SELECTEDVALUE('Table'[YearMonth])
                )
            ),
            [YearMonth]
        )
    )
)

6 months roll total category = 
CALCULATE(
    SUM('Category'[Revenue]),
    FILTER(
        ALL('Category'),
        Category[Category]=SELECTEDVALUE(Category[Category])&&
        'Category'[YearMonth] in 
        TOPN(
            6,
            CALCULATETABLE(
                DISTINCT('Category'[YearMonth]),
                FILTER(
                   ALL('Category'),
                   Category[Category]=SELECTEDVALUE(Category[Category])&&
                   'Category'[YearMonth]<=SELECTEDVALUE('Category'[YearMonth])
                )
            ),
            [YearMonth]
        )
    )
)

 

Result:

b3.png

 

Best Regards

Allan

 

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

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @itsmebvk 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

Category:

b2.png

 

You may create measures as below.

6 months roll total = 
CALCULATE(
    SUM('Table'[Revenue]),
    FILTER(
        ALL('Table'),
        'Table'[YearMonth] in 
        TOPN(
            6,
            CALCULATETABLE(
                DISTINCT('Table'[YearMonth]),
                FILTER(
                   ALL('Table'),
                   'Table'[YearMonth]<=SELECTEDVALUE('Table'[YearMonth])
                )
            ),
            [YearMonth]
        )
    )
)

6 months roll total category = 
CALCULATE(
    SUM('Category'[Revenue]),
    FILTER(
        ALL('Category'),
        Category[Category]=SELECTEDVALUE(Category[Category])&&
        'Category'[YearMonth] in 
        TOPN(
            6,
            CALCULATETABLE(
                DISTINCT('Category'[YearMonth]),
                FILTER(
                   ALL('Category'),
                   Category[Category]=SELECTEDVALUE(Category[Category])&&
                   'Category'[YearMonth]<=SELECTEDVALUE('Category'[YearMonth])
                )
            ),
            [YearMonth]
        )
    )
)

 

Result:

b3.png

 

Best Regards

Allan

 

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

amitchandak
Super User
Super User

@itsmebvk , Create a column like . but have a separate period table

 

Fiscal Month year =[Fiscal Year]*100 + [Fiscal Month]

 

Create a rank on this and do analysis using that. Refer to this week's article. Once you rank it will work n same manner

 

https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

Last 6 period Sales = CALCULATE(SUM(Sales[Net Sales]),FILTER(all('Date'),'Date'[period Rank]>=min('Date'[period Rank])-6 && 'Date'[period Rank]<=max('Date'[period Rank])))

 

here Date will be your period table

 

itsmebvk
Continued Contributor
Continued Contributor

@amitchandak 

 

Thanks Amit for quick reply. I have an issue here, my date table has dates until 2025 and using "Fiscal Period Start Date" and "Fiscal Period End Date" I am able to identify current period I am in. Now using that how we will get rolling 6 months from that particular current period.

@itsmebvk 

The problem with using a YYYYMM column for rolling periods is that the values by definition are not consecutive. For example:

Year Month YYYYMM
2019 11 201911
2019 12 201912
2020 01 202001
2020 02 202002
2020 03 202003

 

so when you want to calculate the rolling 6 months, if you use the YYYYMM value and filter by subtracting 5 months (to have a 6 month total including the current) you might get a period not included. For example:

for the month of March 2020, you would get 202003 - 5 = 201998, which is not a valid YYYYMM value. (Subtracting 5 to get the 6 months including the current)

The easiest way to get around this arguably (as @amitchandak has suggested) is to include an index column for your YYYYMM column in ascending order, and use that in calculations. For example:

YYYYMM YYYYMM Index
201910 1
201911 2
201912 3
202001 4
202002 5
202003 6


To get the rolling average for the last 6 months, you can now subtract 5 from you YYYYMM Index to use in the filter statements in your measures etc...

BTW, if you want to create a YYYYMM index using RANK, you will need the values to be in the format YYYYMM. Otherwise the rank  will not be what you expect: 201912 is a higher value than 20201 (for YYYYM)





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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