Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

IF in DAX Studio

Hi I am trying to create a formula in DAX with IF but I keep getting errors in the bold area, can someone tell me what I am doing wrong?

 

This is what I am trying to create

f_GM/Customer = If(VALIDATED_PD[f_Category_1290] = "GM","GM",VALIDATED_PD[d_Customer_Name])

 

EVALUATE
ADDCOLUMNS(
VALUES( VALIDATED_PD[m_Group_Currency_Amount] ),
"Total Overdue", [a_TotalOverdue],
"Customer Name",
    VAR f_GM_CustomerPD = VALIDATED_PD[d_Customer_Name]
    RETURN
    IF ( f_GM_CustomerPD = "GM", "GM", VALIDATED_PD[d_Customer_Name])
)

8 Replies

  • jiaopengzi's avatar
    jiaopengzi
    Frequent Visitor

    First make sure your business logic is correct.
    1 Does your table `validated_pd` exist?
    2 If your table exists, then your same [d_Customer_Name] will be allocated different [m_Group_Currency_Amount]
    3 If the second item is satisfied, then you should still lack product information, or Say your "GM" needs to be distinct.

  • Hi,

    I am not sure if I understood your question correctly, but please try something like below.

     

    EVALUATE
        ADDCOLUMNS (
            SUMMARIZE (
                VALIDATED_PD,
                VALIDATED_PD[m_Group_Currency_Amount],
                VALIDATED_PD[d_Customer_Name]
            ),
            "Total Overdue", [a_TotalOverdue],
            "Customer Name",
                VAR f_GM_CustomerPD = VALIDATED_PD[d_Customer_Name]
                RETURN
                    IF ( f_GM_CustomerPD = "GM", "GM", VALIDATED_PD[d_Customer_Name] )
        )
    
    • Anonymous's avatar
      Anonymous
      Not applicable

      Is it possible to add more than one IF? for example add to the same code  (last part of the code) (Code in DAX Studio is still running for last code)

       

      f_GM/CustomerNo = IF(VALIDATED_PD[f_GM/Customer] = "GM", BLANK(), VALIDATED_PD[m_Customer_Number])

       

       

      EVALUATE
          ADDCOLUMNS (
              SUMMARIZE (
                  VALIDATED_PD,
                  VALIDATED_PD[m_Group_Currency_Amount],
                  VALIDATED_PD[d_Customer_Name]
              ),
              "Total Overdue", [a_TotalOverdue],
              "Customer Name",
                  VAR f_GM_CustomerPD = VALIDATED_PD[d_Customer_Name]
                  RETURN
                      IF ( f_GM_CustomerPD = "GM", "GM", VALIDATED_PD[d_Customer_Name] ),
              "Customer Number",
                  VAR f_GM_CustomerPD = VALIDATED_PD[d_Customer_Name]
                  RETURN
                      IF ( f_GM_CustomerPD = "GM", BLANK(), VALIDATED_PD[m_Customer_Number] )       
          )

       

       

      • Jihwan_Kim's avatar
        Jihwan_Kim
        Icon for Super User rankSuper User

        Hi,

        Please share your sample pbix file's link with how your expected outcome looks like.

        Thanks.

    • Anonymous's avatar
      Anonymous
      Not applicable

      I have this but the bold part doesn't work the "Customer Number" column, the rest does 

       

      EVALUATE
          ADDCOLUMNS (
              SUMMARIZE (
                  VALIDATED_PD,
                  VALIDATED_PD[m_Group_Currency_Amount],
                  VALIDATED_PD[d_Customer_Name]
              ),
              "Total Overdue", [a_TotalOverdue],
              "Customer Name",
                  VAR f_GM_CustomerPD = VALIDATED_PD[d_Customer_Name]
                  RETURN
                      IF ( f_GM_CustomerPD = "GM", "GM", VALIDATED_PD[d_Customer_Name] ),
              "Customer Number",
                  VAR f_GM_CustomerPD = VALIDATED_PD[d_Customer_Name]
                  VAR f_GM_CustomerNumber = VALIDATED_PD[m_Customer_Number]
                  RETURN
                      IF ( f_GM_CustomerPD = "GM", BLANK(), f_GM_CustomerNumber )       
          )