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
emdnz
Helper I
Helper I

Show top category per year on time chart

Hey all, I feel like I'm very close to the answer but just can't quite conceptualise. 

 

I have a survey I'm processing that has yearly survey submissions across 4 categories of questions. I'm trying to create a bar chart with "year" as x-axis, and the top category based on importance score per year. I've pasted a screenshot below where I've manually highlighted the bars that I want showing in my timeline. So in the final product I'd have a timeline where it shows the category with the max score for that year, then presumably use the 'legend' function to have that impact the colors as well.

 

I'm guessing I could achieve this with a calculated table where each year is 1 row and it shows the max category with the max score? But I just don't quite know how to do this. I've tried some different Top N filters as well but it just seems to show the top N category across the entire dataset rather than show it per year. 

 

Many thanks in advance!

 

YearCompanyCategoryRealityImportance
2020Company 1Across Border Experience3.411.83
2020Company 1Balanced Projects3.422.93
2020Company 1Company and Department Familiarity3.622.74
2020Company 1Duration3.442.6
2020Company 2Across Border Experience2.252
2020Company 2Balanced Projects3.332.94
2020Company 2Company and Department Familiarity3.432.99
2020Company 2Duration3.432.99

 

pbihelp.png

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@emdnz you can easily achieve this by using the new WINDOW DAX function, here is the measure that you can use, change the column and table name as per your model.

 

Also, you can check the full playlist on windows functions here, and more specific to your question, check this video

Subscribe youtube.com/@PowerBIHowTo for Power BI videos.

 

 

//add base measure
Importance Measure = MAX ( 'Table'[Importance] ) 

//add measure to use in the visual to show top category by year
Top Category by Year = 
CALCULATE ( 
    [Importance Measure],
    KEEPFILTERS ( 
        WINDOW (
            1, ABS,
            1, ABS,
            ADDCOLUMNS (
                SUMMARIZE ( 
                    ALL ( 'Table' ),
                    'Table'[Year],
                    'Table'[Category]
                    
                ),
                "@Importance", [Importance Measure]
            ),
            ORDERBY ( [@Importance], DESC ),
            PARTITIONBY ( 'Table'[Year] )
        )
    )
)

 

 



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.

View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@emdnz you can easily achieve this by using the new WINDOW DAX function, here is the measure that you can use, change the column and table name as per your model.

 

Also, you can check the full playlist on windows functions here, and more specific to your question, check this video

Subscribe youtube.com/@PowerBIHowTo for Power BI videos.

 

 

//add base measure
Importance Measure = MAX ( 'Table'[Importance] ) 

//add measure to use in the visual to show top category by year
Top Category by Year = 
CALCULATE ( 
    [Importance Measure],
    KEEPFILTERS ( 
        WINDOW (
            1, ABS,
            1, ABS,
            ADDCOLUMNS (
                SUMMARIZE ( 
                    ALL ( 'Table' ),
                    'Table'[Year],
                    'Table'[Category]
                    
                ),
                "@Importance", [Importance Measure]
            ),
            ORDERBY ( [@Importance], DESC ),
            PARTITIONBY ( 'Table'[Year] )
        )
    )
)

 

 



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.

You are a magician sir, I understand nothing of your measure but it worked! Thank you so much.

@emdnz glad to hear it worked. It is actually very simple measure, I would highly recommend to check the playlist of window dax functions. It will clarify lot of concepts. Good luck. 



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.

amitchandak
Super User
Super User

@emdnz , Use a TOPN Filter on Category

 

or create a TOPN Measure based on Category and use that in Visual

 

Both will have a little bit different behavior

Power BI- TOPN with Others- https://youtu.be/I_TY4hVlzAE

 

Thanks @amitchandak , living up to your super user name. I've tried the top n filter for category but it seems to then show the 1 top category across all years, it doesn't appear to take the top category PER year. Based on the screenshot I shared earlier, I'm expecting 2020 and 2021 to have different categories from all other years based on their avg score (ignore the "max" in the screenshot, that was just me testing)

 

emdnz_0-1674181574161.png

 

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.

Top Solution Authors