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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Power BI DAX function

Demand =
VAR _startdate = MAX('MDS Report'[MDS Date])

VAR LWK = CALCULATE(
    SUM('MDS Report'[Quantity]),
    'MDS Report'[WK] = "LWK",
    'MDS Report'[Week] >= _startdate,
    'MDS Report'[Week] <= _startdate + 91)
VAR CWK = CALCULATE(
    SUM('MDS Report'[Quantity]),
    'MDS Report'[WK] = "CWK",
    'MDS Report'[Week] >= _startdate,
    'MDS Report'[Week] <= _startdate + 91)
VAR Change = SWITCH(
    TRUE(),
        LWK = CWK, 0,
        LWK = 0 && CWK <> 0, 100,
        CWK = 0 && LWK <> 0, -100,
        LWK <> 0, DIVIDE((CWK-LWK), LWK, 0) * 100 )
VAR _total =
    IF(ISBLANK(MAX('MDS Report'[Month])), 0,
        IF(DISTINCTCOUNT('MDS Report'[Month])>1,
        FORMAT(Change, "0.00") & " %",
        FORMAT(SUM('MDS Report'[Quantity]), "")
        )
    )
   
RETURN COALESCE(_total, 0)
sk2024_1-1725599122679.png

As marked by highlighter, Some null values are not showing 0. What should I do in that case? 
I have attached the dax code with it.
Please give the solution.

3 REPLIES 3
Anonymous
Not applicable

Hi, @Anonymous 

Thanks for rajendraongole1 reply. Have you currently resolved this issue, and if not, could you please share the pbix file without sensitive data to test.

Best Regards,
Yang
Community Support Team



rajendraongole1
Super User
Super User

Hi @Anonymous -I have modify the code slightly. The issue might arise from how LWK or CWK variables using the coalese function there to handle blanks. 

Demand =
VAR _startdate = MAX('MDS Report'[MDS Date])

VAR LWK = CALCULATE(
SUM('MDS Report'[Quantity]),
'MDS Report'[WK] = "LWK",
'MDS Report'[Week] >= _startdate,
'MDS Report'[Week] <= _startdate + 91
)
VAR CWK = CALCULATE(
SUM('MDS Report'[Quantity]),
'MDS Report'[WK] = "CWK",
'MDS Report'[Week] >= _startdate,
'MDS Report'[Week] <= _startdate + 91
)

-- Ensure LWK and CWK return 0 if they are BLANK
VAR LWK_Valid = COALESCE(LWK, 0)
VAR CWK_Valid = COALESCE(CWK, 0)

VAR Change = SWITCH(
TRUE(),
LWK_Valid = CWK_Valid, 0,
LWK_Valid = 0 && CWK_Valid <> 0, 100,
CWK_Valid = 0 && LWK_Valid <> 0, -100,
LWK_Valid <> 0, DIVIDE((CWK_Valid - LWK_Valid), LWK_Valid, 0) * 100
)

VAR _total =
IF(ISBLANK(MAX('MDS Report'[Month])), 0,
IF(DISTINCTCOUNT('MDS Report'[Month]) > 1,
FORMAT(Change, "0.00") & " %",
FORMAT(SUM('MDS Report'[Quantity]), "")
)
)

RETURN COALESCE(_total, 0)

 

Hope it works, please check





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

Proud to be a Super User!





Anonymous
Not applicable

Sorry,

But it is still showing blank with no 0.

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.