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

Bar Chart comparing monthly volume to Average monthly volume YTD

I need to create a bar chart that displays the current monthly total across 3 seperate categories (Category 1, 2, 3) and also displays the average monthly volume YTD for all three categories. The goal is to show how the current months volume for each category compares proportionaly to the YTD volume.

 

I'm able to create the bar chart with volume from January - May 2020 for each category but am unable to create a line showing the average YTD volume for each category due to the monthly filter in the bar chart. Do I need to use DAX to overcome this issue? Would appreciate any help?

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

Hi,

 

Please try these measures:

Current Month = 
IF (
    MONTH ( MAX ( 'Table'[Date] ) ) = MONTH ( TODAY () ),
    SUM ( 'Table'[Values] )
)
YTD = 
VAR a =
    SUMMARIZE (
        ALLSELECTED ( 'Table' ),
        'Table'[Date],
        'Table'[Category],
        "YTD", CALCULATE (
            SUM ( 'Table'[Values] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[Category] IN FILTERS ( 'Table'[Category] )
                    && 'Table'[Date] <= MAX ( 'Table'[Date] )
            )
        )
    )
RETURN
    AVERAGEX ( FILTER ( a, [Date] IN FILTERS ( [Date] ) ), [YTD] )

The result shows:

10.PNG

See my attached pbix file.

 

Best Regards,

Giotto

View solution in original post

7 REPLIES 7
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please try these measures:

Current Month = 
IF (
    MONTH ( MAX ( 'Table'[Date] ) ) = MONTH ( TODAY () ),
    SUM ( 'Table'[Values] )
)
YTD = 
VAR a =
    SUMMARIZE (
        ALLSELECTED ( 'Table' ),
        'Table'[Date],
        'Table'[Category],
        "YTD", CALCULATE (
            SUM ( 'Table'[Values] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[Category] IN FILTERS ( 'Table'[Category] )
                    && 'Table'[Date] <= MAX ( 'Table'[Date] )
            )
        )
    )
RETURN
    AVERAGEX ( FILTER ( a, [Date] IN FILTERS ( [Date] ) ), [YTD] )

The result shows:

10.PNG

See my attached pbix file.

 

Best Regards,

Giotto

parry2k
Super User
Super User

@wquayle yes you have to create a measure to calculate YTD avg. As a best practice, add date dimension in your model and use it for and time intelligence calculations. Once the date dimension is added, mark it as a date table on table tools.

https://perytus.com/2020/05/22/create-a-basic-date-table-in-your-data-model-for-time-intelligence-ca...

 

YTD AVG = CALCULATE ( AVERGATE( Table[Column] ), DATESYTD ( DateTable[Date] ) ) 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos 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.

Appreciate your response and will absolutely provide Kudos. When I use the formula from your site the date, I get the following error message, "The column 'Year' in table 'Date' has invalid bindings specified." I deleted this line of code, and received another message, "The column Month' in table 'Date' has invalid bindings specified. Can you advise how to resolve this issue? Thank you, again!

@wquayle is this related to my post? What you are referring too? 



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.

 

Hi,

 

If my previous reply has solved your issue, please mark it as a solution for others to see.

 

Best Regards,

Giotto

I appreciate your formulas and feedback. How would I re-write the formula to show data from the previous month instead of the current month?

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.