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
sakuragihana
Helper IV
Helper IV

Need help to apply a condition for dax

Hello everyone, I have a report to calculate bonus of staff as : sakuragihana_0-1676369589214.png

Bonus for new student enrollment

 Bonus  =Number of New Student PD x Bonus of group

  -Apply for condition type NEW ENROLLMENT  : 

      1. Area code : HCMC, SouthArea

      2.% Act vs Target of Campus is greater than and equal 80% 

      3.# of New Student PD is greater than and equal 5

sakuragihana_1-1676370119074.png

sakuragihana_2-1676370264271.png

Another conditions apply for type NEW ENROLLMENT

1. Campus code : NewArea, VT Area

2.% Act vs Target of Campus is greater than and equal 75% 

3.# of New Student PD is greater than and equal 3

sakuragihana_3-1676370286352.png

 

sakuragihana_4-1676370286337.png

 

Dax for calculating this report: 

 

------------------------------------------------------------------------------------------------------------------------------------

Bonus_new_enroll =
VAR dateselect = SELECTEDVALUE('ASA Bonus Starget'[Date key])
VAR datekey = CALCULATE(MIN('Calendar'[Date Key]), 'Calendar'[Date Key]=VALUE(dateselect))
VAR area  = SELECTEDVALUE('Campus'[Area Code])
VAR new_students = 'ASA Overview PD'[# of New Student PD]
var Pct_target = 'ASA Overview PD'[% of New Student PD vs Campus Target]
VAR filtered_areas =
    CALCULATETABLE(
        DISTINCT('Campus'[Area Code]),
        OR (
            'Campus'[Area Code] IN { "HCMC", "SouthArea"} && Pct_target >0.8,
            'Campus'[Area Code] IN {"NewArea", "VT Area" } && Pct_target >0.75
        )
       
    )
VAR bonus_1_t =
    FILTER (
        'ASA Bonus Starget',
        'ASA Bonus Starget'[Min] <= new_students
         && 'ASA Bonus Starget'[Area Code Campus] = area
         && 'ASA BOnus Starget'[Type] = "NEW ENROLLMENT"
         && VALUE('ASA Bonus Starget'[Date key]) = datekey
    )
VAR bonuses_calc_1 =
    SUMX (
        ADDCOLUMNS (
            bonus_1_t,
            "@bonus_calc1",
                VAR current_bonus = [Bonus 1]
                VAR prev_limit_running = SUMX ( FILTER ( bonus_1_t, [Bonus 1] < current_bonus ), [Max] )
                VAR students_diff = new_students - prev_limit_running
                VAR students = IF ( students_diff < 0, BLANK (), students_diff )
                RETURN
                    MIN ( [Max], students ) * [Bonus 1]
        ),
        [@bonus_calc1]
    )
    VAR bonus_new_enrollment = IF ( area in filtered_areas, bonuses_calc_1 )
Return bonus_new_enrollment

---------------------------------------------------------------------------------------------------------------------------------------

I use this dax to calculate bonus for staff. But I have a problem , the condition [% Act vs Target of Campus] is greater than and equal 80% is applied for a whole of campus not for everyone belong of campus. 

Example :

sakuragihana_5-1676370792274.png

The dax just calculate for staff who is [% Act vs Target] 107% and not calculate for 2 staffs . I need the dax apply for whole campus which [% Act vs Target] is greater than 80% (as Campus code ADV is 161%)  , not for [% Act vs Target] of staff is greater than 80%

Similarly,  the condition [% Act vs Target of Campus] is greater than and equal 75% is applied for a whole of campus.

 

I post plib in this link : https://app.powerbi.com/groups/me/reports/ac39c2eb-d6d9-46d6-9f87-3fe72272633e?ctid=d1005fc5-bff9-42... 

 

Can everyone help me to fix that dax ?

 

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @sakuragihana,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Notice: please exclude sensitive data before sharing.

Regards,

Xiaoxin Sheng

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

Hi @v-shex-msft ,

 

Please use this link : https://app.powerbi.com/groups/me/reports/ac39c2eb-d6d9-46d6-9f87-3fe72272633e?ctid=d1005fc5-bff9-42... 

 

Dax in sheet Bonus Sale Performance . Although, the dax of bonus_new_revenue and the dax of bonus_re_enroll is the same ,  I need the dax apply for all of staff who satisfy the conditions . Can you help me to fix that dax ?

Hi @sakuragihana,

In fact, the shared report link does not help, I can't view these shared contents.

Perhaps you can create some dummy data with similar structure and Dax expressions in a sample pbix file and share here. They will help us test to coding formula and troubleshoot on your scenario.

Regards,

Xiaoxin Sheng

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

Hi @v-shex-msft ,

Can you give me your email  ? So I will share a report link for you

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.

Top Solution Authors