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

Dynamically select last month in bar chart

Hello ,

 

I have a bar chart in Power BI and I am trying to dynamically keep the bar correspoding to last month selected. The intention is to show the numbers for other metrics based on last month and also give the option to select bars corresponding to other months if the user wants to see specifically for any month. Is this possible ?

 

Dilpreeth_0-1598445407456.png

 

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

Hi @Anonymous ,

 

Please try this:

 

A disconnected table:

Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

Measures:

Total sales =
VAR selectedsales =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER (
            'Table',
            'Table'[Date].[Month] = SELECTEDVALUE ( 'Date'[Date].[Month] )
        )
    )
RETURN
    IF (
        ISFILTERED ( 'Date'[Date].[Month] ),
        selectedsales,
        CALCULATE ( SUM ( 'Table'[Sales] ) )
    )

 

Measure =
VAR maxdate =
    MAXX ( ALL ( 'Table' ), 'Table'[Date] )
RETURN
    IF (
        ISFILTERED ( 'Date'[Date].[Month] ),
        "Blue",
        IF ( MAX ( 'Table'[Date] ) = maxdate, "Blue", "Gray" )
    )

 highlight bars by default.gif

 

You could reference the document to learn more about conditional formatting and change other colors in the formula.

https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-conditional-table-formatting#color-based-on-a-calculation

 

 

Best Regards,
Xue Ding
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
Anonymous
Not applicable

Thank You @amitchandak  @v-xuding-msft ...appreciate the help 

v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try this:

 

A disconnected table:

Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

Measures:

Total sales =
VAR selectedsales =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER (
            'Table',
            'Table'[Date].[Month] = SELECTEDVALUE ( 'Date'[Date].[Month] )
        )
    )
RETURN
    IF (
        ISFILTERED ( 'Date'[Date].[Month] ),
        selectedsales,
        CALCULATE ( SUM ( 'Table'[Sales] ) )
    )

 

Measure =
VAR maxdate =
    MAXX ( ALL ( 'Table' ), 'Table'[Date] )
RETURN
    IF (
        ISFILTERED ( 'Date'[Date].[Month] ),
        "Blue",
        IF ( MAX ( 'Table'[Date] ) = maxdate, "Blue", "Gray" )
    )

 highlight bars by default.gif

 

You could reference the document to learn more about conditional formatting and change other colors in the formula.

https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-conditional-table-formatting#color-based-on-a-calculation

 

 

Best Regards,
Xue Ding
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

@Anonymous , with only one measure you should be able to do conditional formatting. you can create a measure like this

example

Color Date = if(FIRSTNONBLANK('Date'[Date],TODAY()) <today(),"lightgreen","red")

 

Then use it in conditional formatting

https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-numbers-in-the-column
https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

 

If conditional formatting is not available under the data label. try something like this to put a dot

https://community.powerbi.com/t5/Community-Blog/Display-Label-Only-on-the-Last-Data-Point-of-the-Line-Visual-for/ba-p/1253464

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.