Forum Discussion

LABrowne's avatar
LABrowne
Helper II
2 years ago
Solved

Complex Conditional Calculation Formula

Hi there,   I have the following dax code: (1) V2 Net Sales = SUMX(     VALUES(AdjustmentType[AdjustmentTypeId]),     SWITCH(AdjustmentType[AdjustmentTypeId],     2, [V1 Gross Tax Sales], ...
  • 123abc's avatar
    123abc
    2 years ago

    I see, if you're encountering an issue with having multiple columns in the VALUES function, you can modify the code to use a combination of CALCULATETABLE and FILTER. Here's an updated version of the code:

     

    V2 Net Sales =
    SUMX(
    VALUES(AdjustmentType[AdjustmentTypeId]),
    SWITCH(
    TRUE(),
    AdjustmentType[AdjustmentTypeId] = 2, [V1 Gross Tax Sales],
    AdjustmentType[AdjustmentTypeId] = 1,
    IF (
    CALCULATE(
    COUNTROWS(
    FILTER(
    Contract,
    Contract[ContractTable] = 22
    )
    )
    ) > 0,
    ([V1 Net Before Tax Sales] / [Order Period]) * [Days Since Order],
    [V1 Net Before Tax Sales]
    ),
    AdjustmentType[AdjustmentTypeId] = 3, [V1 Net Before Tax Sales],
    AdjustmentType[AdjustmentTypeId] = 4, [V1 Net Before Tax Sales],
    AdjustmentType[AdjustmentTypeId] = 5, [V1 Net Before Tax Sales],
    BLANK()
    )
    )

     

    In this version, I've used CALCULATE along with COUNTROWS and FILTER to check if there is any row in the Contract table where ContractTable is equal to 22. If true, it applies the specified formula; otherwise, it uses [V1 Net Before Tax Sales]. Adjust the column and table names as needed based on your data model.

     

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

     

    In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.