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
tallen
Regular Visitor

Help with DAX Group By ignoring visual filters

Hi all,

 

I am having trouble with a DAX formula.  I am trying to group some employee data together to calculate an average hourly rate when they have multiple positions, rank the hourly rate in descending order, and use this to split the data into four equal "quartiles".  This result would then be displayed split by the number of employees of each gender.  I think the issue I am having is because the filter from the visual is filtering the data before the calculation.

 

I am trying to keep this all within one measure to allow for dynamic filtering by various characteristics and position types that become grouped together in the calculation.

 

Currently this is what I have:

 

Q1 = 
VAR grouped_table =         
GROUPBY(
    fct_gender_pay_gap,
    fct_gender_pay_gap[snapshot_date_ref],
    dim_employee[Employee ID],
    dim_diversity[Gender],
    "Total Hourly Rate",SUMX(CURRENTGROUP(),fct_gender_pay_gap[hourly_rate]*fct_gender_pay_gap[fpe])
)
VAR added_columns = 
ADDCOLUMNS(
    grouped_table,
    "Rank Quartiles", IF(RANKX(grouped_table,[Total Hourly Rate] + ([Employee ID] / POWER(10,7))) / COUNTROWS(grouped_table) <= 0.25, 4,
                    IF(RANKX(grouped_table,[Total Hourly Rate] + ([Employee ID] / POWER(10,7))) / COUNTROWS(grouped_table) <= 0.5, 3,
                    IF(RANKX(grouped_table,[Total Hourly Rate] + ([Employee ID] / POWER(10,7))) / COUNTROWS(grouped_table) <= 0.75, 2, 1)))
)
RETURN
COUNTAX(FILTER(added_columns,[Rank Quartiles]=1),dim_employee[Employee ID])

 

 

This splits the data into 4 evenly sized quartiles, but if I split the data by gender it will give me 4 equal quartiles of males and 4 equal quartiles of females, which is not the desired output. 

 

Current result:

QuartileFemaleMale
12515
22515
32515
42515

 

Desired result:

QuartileFemaleMale
13010
22020
32515
41228

 

Below is a copy of my schema:

schema.png

 

Any help would be greatly appreciated.

 

Kind regards,

 

Thomas.

2 REPLIES 2
v-jayw-msft
Community Support
Community Support

Hi @tallen ,

 

It's hard to modify the formula with out any data. You have provided the expected result but we still need some sample data so that we could help you deal with formula.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
MFelix
Super User
Super User

Hi @tallen ,

 

Altough your information is complete, the data for your model is not clear, can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.