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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
gattoun
Frequent Visitor

DAX Query - Display Difference Between Two Datasets

I'm building a tornado chart that displays average salary differences by gender and pay grade. For each pay grade, I'd like to have ONE bar on the left (female) or right (male) showing the difference in average pay for that grade. If only one gender is present in that grade, then there shouldn't be a bar. The logic should be something like "if two genders are present in this pay grade, then take average of each gender and subtract smaller from larger, and add a flag stating which gender is larger." So I'm thinking I need both a new measure (the difference) and a new column (the gender flag). Attempted DAX query and chart output:

https://ibb.co/bBE60m

 

https://ibb.co/eVJYfm

 

How can I structure a DAX query to accomplish this? 

1 ACCEPTED SOLUTION
alena2k
Resolver IV
Resolver IV

I have alternative visual solution. Try and see if you like it.  At least it should take you half way there.

Create 2 measures and display both of them as values it on your tornado control:

 

Advantage F = 
VAR
  avgF = CALCULATE(AVERAGE(tbl[salary]), tbl[Gender] ="F")
VAR
  avgM = CALCULATE(AVERAGE(tbl[salary]), tbl[Gender] ="M")
VAR
  gap   = avgM - avgF
RETURN
  IF(	gap > 0 || avgF = 0 || avgM = 0, 0, abs(gap))

 

 

Advantage M = 
VAR
  avgF = CALCULATE(AVERAGE(tbl[salary]), tbl[Gender] ="F")
VAR
  avgM = CALCULATE(AVERAGE(tbl[salary]), tbl[Gender] ="M")
VAR
  gap   = avgM - avgF
RETURN
  IF(	gap <= 0 || avgF = 0 || avgM = 0, 0, gap)

As a result you will have presence of the bar as indicator on which gender has advantage. I hope it will help.

View solution in original post

4 REPLIES 4
alena2k
Resolver IV
Resolver IV

I have alternative visual solution. Try and see if you like it.  At least it should take you half way there.

Create 2 measures and display both of them as values it on your tornado control:

 

Advantage F = 
VAR
  avgF = CALCULATE(AVERAGE(tbl[salary]), tbl[Gender] ="F")
VAR
  avgM = CALCULATE(AVERAGE(tbl[salary]), tbl[Gender] ="M")
VAR
  gap   = avgM - avgF
RETURN
  IF(	gap > 0 || avgF = 0 || avgM = 0, 0, abs(gap))

 

 

Advantage M = 
VAR
  avgF = CALCULATE(AVERAGE(tbl[salary]), tbl[Gender] ="F")
VAR
  avgM = CALCULATE(AVERAGE(tbl[salary]), tbl[Gender] ="M")
VAR
  gap   = avgM - avgF
RETURN
  IF(	gap <= 0 || avgF = 0 || avgM = 0, 0, gap)

As a result you will have presence of the bar as indicator on which gender has advantage. I hope it will help.

This is perfect. Thank you so much!

Anonymous
Not applicable

Hi @gattoun,

 

If you can, please share the pbix file for further testing. It is hard to clarify your scenario from screenshots.

BTW, please do mask sensitive data if your contents contains any privacy data.


Regards,

Xiaoxin Sheng

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.