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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
rit_ty7
Advocate I
Advocate I

Help with the dax formula

Hello everyone, is the below formula correct for calculating productive calls(pc) for lighting?

PC Total Call_lighting =
var a = CALCULATE(COUNT(SECONDARY_VISIT_DATA_NEW[VISIT_ID]), FILTER(SECONDARY_VISIT_DATA_NEW, SECONDARY_VISIT_DATA_NEW[NON_PRODUCTIVE] = "NO"))
var b = CALCULATE(a, FILTER(MATERIAL_ATTRIBUTES_CL, MATERIAL_ATTRIBUTES_CL[MAIN_GROUP] IN {"Conventional", "D-Lite", "Elect. Accessories", "LED Battens", "LED Lamps", "LED Outdoors"}))
RETURN
b
3 REPLIES 3
danextian
Super User
Super User

Hi @rit_ty7 

It is important to note that variables in DAX are immutable, meaning their values cannot be altered using CALCULATE to modify their context. For example, if a variable like var a is defined, its context cannot be changed after assignment in var b. As shown in the screenshot, the _LY measure is expected to return the value for 2023, but instead, it continues to return values for each individual year due to the immutability of the variable.

 

danextian_0-1737124658475.png

Try this measure instead.

CALCULATE (
    COUNT ( SECONDARY_VISIT_DATA_NEW[VISIT_ID] ),
    KEEPFILTERS ( SECONDARY_VISIT_DATA_NEW[NON_PRODUCTIVE] = "NO"
        && MATERIAL_ATTRIBUTES_CL[MAIN_GROUP]
        IN {
            "Conventional",
            "D-Lite",
            "Elect. Accessories",
            "LED Battens",
            "LED Lamps",
            "LED Outdoors"
        } )
)

The above represents an optimized version of your original measure. Instead of applying FILTER to the entire table, focus it only on the relevant columns. Use KEEPFILTERS to intersect filters, rather than override the existing filter context in DAX. For example, the value will only be calculated if SECONDARY_VISIT_DATA_NEW[NON_PRODUCTIVE] = No and MATERIAL_ATTRIBUTES_CL[MAIN_GROUP] are included in your list. This ensures that the calculation is specific to those conditions and is not applied to all rows.

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Abhijeet_40
Helper I
Helper I

Hello!

Just a couple of questions. Why are using filter and using an inline method:
PC Total Call_lighting =
CALCULATE(
COUNT(SECONDARY_VISIT_DATA_NEW[VISIT_ID]),
SECONDARY_VISIT_DATA_NEW[NON_PRODUCTIVE] = "NO",
MATERIAL_ATTRIBUTES_CL[MAIN_GROUP] IN {
"Conventional",
"D-Lite",
"Elect. Accessories",
"LED Battens",
"LED Lamps",
"LED Outdoors"
}
)

If this won't work for you. Why not use both the filter block in a single calculate block?

Ritaf1983
Super User
Super User

Hi @rit_ty7 

Please share sample data (excluding sensitive information) in text format, along with your expected result and any relevant logic. For guidance, refer to

How to provide sample data in the Power BI Forum

If possible, upload a simplified .pbix file using this guide:

 How to upload PBI in Community

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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