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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Getting sum of a group of values then showing max value

Hi,

 

I've been experimenting with building a US Election Dashboard but I'm struggling with the following data. Here's an example.

data.PNG

What I'd like to do is insert a column after that simply states "REP" or "DEM" based on who has the most votes. The difficulty for me is the DAX required to first:
- Sum up total votes in each state for each party
- Compare both values and display the greater

 

Any help would be appreciated

 

UPDATE:

Managed to get halfway there, summing up the totals for each state ( see below)

data2.PNG

 

Sum of State = CALCULATE(SUM(president_county_candidate[votes]), ALLEXCEPT(president_county_candidate,president_county_candidate[state],president_county_candidate[party]))

 

Now I'm stuck on how to display REP or DEM based on which value is greater

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

HI @Anonymous,

You can use the following calculated table formula to output larger records from aggregated table records: 

 

Summary table =
VAR summary =
    SUMMARIZE ( Table, [state], [party], "t_votes", SUM ( Table[votes] ) )
RETURN
    FILTER (
        summary,
        [t_votes]
            = MAXX ( FILTER ( summary, [state] = EARLIER ( [state] ) ), [t_votes] )
    )

 

15.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @Anonymous,

You can use the following calculated table formula to output larger records from aggregated table records: 

 

Summary table =
VAR summary =
    SUMMARIZE ( Table, [state], [party], "t_votes", SUM ( Table[votes] ) )
RETURN
    FILTER (
        summary,
        [t_votes]
            = MAXX ( FILTER ( summary, [state] = EARLIER ( [state] ) ), [t_votes] )
    )

 

15.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.