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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.