Forum Discussion

tallen's avatar
tallen
Regular Visitor
5 years ago

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:

 

Any help would be greatly appreciated.

 

Kind regards,

 

Thomas.

2 Replies

  • 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.

  • Anonymous's avatar
    Anonymous
    Not applicable

    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