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
harirao
Post Prodigy
Post Prodigy

DAX calculation

Hi All,

I have created an excel formula, which is basically comparing 4 columns using IF, AND & SUMIF functions
Excel formula:
=IF(AND(Q2>M2,SUMIFS($Q:$Q,$A:$A,$A2,$J:$J,$J2)>=SUMIFS($M:$M,$A:$A,$A2,$J:$J,$J2)),"Not enough fcst on the VT",IF(AND(Q2>M2,SUMIFS($Q:$Q,$A:$A,$A2,$J:$J,$J2)<=SUMIFS($M:$M,$A:$A,$A2,$J:$J,$J2)),"Enough fcst on the VT but not on the Loc","Enough fcst on the VT & Loc"))
C1.PNG

Similar to excel formula, tried to create a new DAX but I am getting bellow error 
"Total Demand" is only Measure created others are direct columns from 'Main Table'
TEST =

IF(AND('Main Table'[Total Demand] > 'Main Table'[Final Fcst],
        CALCULATE(
            SUM('Main Table'[Total Demand]),
            FILTER(ALL('Main Table'[Product], 'Main Table'[Time[Month]]),
                'Main Table'[Product] = EARLIER('Main Table'[Product]) && 'Main Table'[Time[Month]] = EARLIER('Main Table'[Time[Month]])
            )) >= CALCULATE(
            SUM('Main Table'[Final Fcst]),
            FILTER(ALL('Main Table'[Product], 'Main Table'[Time[Month]]),
                'Main Table'[Product] = EARLIER('Main Table'[Product]) && 'Main Table'[Time[Month]] = EARLIER('Main Table'[Time[Month]])
            ))),
    "Not enough fcst on the VT",
    IF(AND('Main Table'[Total Demand] > 'Main Table'[Final Fcst],
            CALCULATE(SUM('Main Table'[Total Demand]),
                FILTER(ALL('Main Table'[Product], 'Main Table'[Time[Month]]),
                    'Main Table'[Product] = EARLIER('Main Table'[Product]) && 'Main Table'[Time[Month]] = EARLIER('Main Table'[Time[Month]])
                )) <= CALCULATE(SUM('Main Table'[Final Fcst]),
                FILTER(ALL('Main Table'[Product], 'Main Table'[Time[Month]]),
                    'Main Table'[Product] = EARLIER('Main Table'[Product]) && 'Main Table'[Time[Month]] = EARLIER('Main Table'[Time[Month]])
                ))),"Enough fcst on the VT but not on the Loc",
        "Enough fcst on the VT & Loc"))))))))))))
Error: The end of the input was reached.

Please assist me to resolve this issue
 
Thank you.
1 REPLY 1
marcelsmaglhaes
Super User
Super User

Hey @harirao 

 

In your DAX has a lot of brackets and parentheses left over.  Take a look at the clean DAX below. I did not check the logic of the DAX,  I just check the brackets and parentheses. If not works, maybe you should try to use the SWITCH function (SWITCH function (DAX) - DAX | Microsoft Learn). It's easier to write than a cascade IF.

 

Kind Regards, 
Marcel

** If this posts helps, please consider mark it as solved. 

 

TEST =
IF (
AND (
'Main Table'[Total Demand] > 'Main Table'[Final Fcst],
CALCULATE (
SUM ( 'Main Table'[Total Demand] ),
FILTER (
ALL ( 'Main Table'[Product], 'Main Table'[Time[Month] ),
'Main Table'[Product] = EARLIER ( 'Main Table'[Product] )
&& 'Main Table'[Time[Month] = EARLIER ( 'Main Table'[Time[Month] )
)
)
>= CALCULATE (
SUM ( 'Main Table'[Final Fcst] ),
FILTER (
ALL ( 'Main Table'[Product], 'Main Table'[Time[Month] ),
'Main Table'[Product] = EARLIER ( 'Main Table'[Product] )
&& 'Main Table'[Time[Month]] = EARLIER('Main Table'[Time[Month]
)
)
),
"Not enough fcst on the VT",
IF (
AND (
'Main Table'[Total Demand] > 'Main Table'[Final Fcst],
CALCULATE (
SUM ( 'Main Table'[Total Demand] ),
FILTER (
ALL ( 'Main Table'[Product], 'Main Table'[Time[Month] ),
'Main Table'[Product] = EARLIER ( 'Main Table'[Product] )
&& 'Main Table'[Time[Month] = EARLIER ( 'Main Table'[Time[Month] )
)
)
<= CALCULATE (
SUM ( 'Main Table'[Final Fcst] ),
FILTER (
ALL ( 'Main Table'[Product], 'Main Table'[Time[Month] ),
'Main Table'[Product] = EARLIER ( 'Main Table'[Product] )
&& 'Main Table'[Time[Month] = EARLIER ( 'Main Table'[Time[Month] )
)
)
),
"Enough fcst on the VT but not on the Loc",
"Enough fcst on the VT & Loc"
)
)

 

 


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!
Imagem de fundo



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.