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

Cummulative bar chart to hide set of certain months and display last 6 months data.

Was trying to display cummulative count of the id by months but i have almost 3+ yrs data but i need to show last 6 month trend.

If i  do filter on 

id_Cum_Cnt = CALCULATE(
    'tst'[id_count],
    FILTER(
        ALL('tst),
        'tst'[CREATE_DATE] <= MAX ('tst'[CREATE_DATE])
    )
)
and showing cumulative only for these 6 months, 
Need help to hide the other months data and still consider instead of starting from 0.
 
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Sarath5c8 ,

 

There is something wrong in parry2k's code. I suggest you to try this measure to achieve your goal.

id_Cum_Cnt =
VAR __within6months =
    DATEDIFF (
        MIN ( 'tst'[CREATE_DATE] ),
        EOMONTH ( MAXX ( ALL ( tst ), tst[CREATE_DATE] ), 0 ),
        MONTH
    ) < 6
RETURN
    IF (
        __within6months,
        CALCULATE (
            'tst'[id_count],
            FILTER ( ALL ( 'tst' ), 'tst'[CREATE_DATE] <= MAX ( 'tst'[CREATE_DATE] ) )
        )
    )

My Sample has data from 2020/01/01 to 2022/08. Result is as below.

RicoZhou_0-1661241740720.png

 

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Sarath5c8 ,

 

There is something wrong in parry2k's code. I suggest you to try this measure to achieve your goal.

id_Cum_Cnt =
VAR __within6months =
    DATEDIFF (
        MIN ( 'tst'[CREATE_DATE] ),
        EOMONTH ( MAXX ( ALL ( tst ), tst[CREATE_DATE] ), 0 ),
        MONTH
    ) < 6
RETURN
    IF (
        __within6months,
        CALCULATE (
            'tst'[id_count],
            FILTER ( ALL ( 'tst' ), 'tst'[CREATE_DATE] <= MAX ( 'tst'[CREATE_DATE] ) )
        )
    )

My Sample has data from 2020/01/01 to 2022/08. Result is as below.

RicoZhou_0-1661241740720.png

 

Best Regards,
Rico Zhou

 

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

parry2k
Super User
Super User

@Sarath5c8 first and foremost when you are working with dates, it is a best practice to add a calendar dimension to your model, you can check the time intelligence series on my YouTube channel https://www.youtube.com/watch?v=BKzsCfr4qeQ&list=PLiYSIjh4cEx2FkuGkngYruS0wm8MYFsoi&index=12

 

to return blank prior to 6 months, you can do something like this:

 

d_Cum_Cnt = 
VAR __within6months = DATEDIFF ( MAX ( MAX ('tst'[CREATE_DATE] ), TODAY (),  Month )  >= 6
RETURN
IF ( __within6months ),
CALCULATE(
    'tst'[id_count],
    FILTER(
        ALL('tst),
        'tst'[CREATE_DATE] <= MAX ('tst'[CREATE_DATE])
    )
)
)

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.