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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
qqqube
New Member

question about the formula of hasonevalue

dax-power-bi-modify-filter/4-examine-filter-context 

in this training module, it gives us an example of HAVEONEVALUE formula as follows 

 

 

Sales Commission =
[Revenue]
    * IF(
        HASONEVALUE('Sales Territory'[Country]),
        IF(
            VALUES('Sales Territory'[Country]) = "United States",
            0.15,
            0.1
        )
    )

 

112.png and it tell us that the reason why total of sales commission is blank is because HASONEVALUE('Sales Territory'[Country]) return FALSE. 

so I tried to change it to HASONEVALUE('Sales Territory'[Region]) as the values in [Region] column are unique. but still total of sales commission is blank.

 

Please explain why. thx.

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@qqqube The HASONEVALUE function returns TRUE only when there is exactly one distinct value in the specified column within the current filter context. When you are looking at the total of the sales commission, the filter context typically includes multiple values from the 'Sales Territory'[Region] column, which causes HASONEVALUE to return FALSE.

 

 

Filter Context at Total Level: When calculating the total, the filter context includes all regions, not just one. Therefore, HASONEVALUE('Sales Territory'[Region]) returns FALSE because there are multiple regions in the context of the total.

 

Blank Result: Since HASONEVALUE returns FALSE, the IF condition is not met, and the formula does not proceed to calculate the commission, resulting in a blank value for the total.

 

To address this, you can modify the formula to handle the total calculation separately. One way to do this is by using the SUMX function to iterate over each row and calculate the commission individually, then sum the results:




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

1 REPLY 1
bhanu_gautam
Super User
Super User

@qqqube The HASONEVALUE function returns TRUE only when there is exactly one distinct value in the specified column within the current filter context. When you are looking at the total of the sales commission, the filter context typically includes multiple values from the 'Sales Territory'[Region] column, which causes HASONEVALUE to return FALSE.

 

 

Filter Context at Total Level: When calculating the total, the filter context includes all regions, not just one. Therefore, HASONEVALUE('Sales Territory'[Region]) returns FALSE because there are multiple regions in the context of the total.

 

Blank Result: Since HASONEVALUE returns FALSE, the IF condition is not met, and the formula does not proceed to calculate the commission, resulting in a blank value for the total.

 

To address this, you can modify the formula to handle the total calculation separately. One way to do this is by using the SUMX function to iterate over each row and calculate the commission individually, then sum the results:




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.