Forum Discussion

thampton's avatar
thampton
Icon for Helper III rankHelper III
7 years ago
Solved

DAX Help with VAR measure statement

I have a table like the one shown below. I need to create a measure that can dynamically show totals based on a selected date. 

 

Tables: 

1. Date table

2. Orders

 

Table Structure:

Order       Orig .Amount            Current Amount        Inv Date         Inv Paid

1              10                               2                               1/2/2019        1/5/2019

2              20                               0                               1/10/2019      1/20/2019

 

I currently have the date field from my date table as a slicer. And have a var statement below that will calculate the total based on the selected date and the inv date. However, it does not take into account the balance due column. So if my Selected Date is > Inv Date but < the Paid Date, it needs to sum the Orig Amount, as it has not been paid yet. If the Selected date is > Inv Paid it needs to sum the Current Amount. 

 

Example. I selected 1/15/2019. For order 1, the selected date > Paid Date, so i should calculate as 2. For order 2 the selected date is < Paid Date so this should calculate as the orig. amount of 20. How can i write a measure that will equal 22?

 

  • Hi thampton,

    If you want to calculate total value based on date, you could try below measure to see whether it works or not

    total =
    CALCULATE (
        SUM ( 'order'[orig.amount] ),
        FILTER (
            'order',
            'order'[inv date] <= SELECTEDVALUE ( 'date'[Date] )
                && 'order'[inv paid] >= SELECTEDVALUE ( 'date'[Date] )
        )
    )
        + CALCULATE (
            SUM ( 'order'[current amount] ),
            FILTER ( 'order', SELECTEDVALUE ( 'date'[Date] ) > 'order'[inv paid] )
        )

    Best Regards,

    Zoe Zhi

     

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

1 Reply

  • dax's avatar
    dax
    Icon for Community Support rankCommunity Support

    Hi thampton,

    If you want to calculate total value based on date, you could try below measure to see whether it works or not

    total =
    CALCULATE (
        SUM ( 'order'[orig.amount] ),
        FILTER (
            'order',
            'order'[inv date] <= SELECTEDVALUE ( 'date'[Date] )
                && 'order'[inv paid] >= SELECTEDVALUE ( 'date'[Date] )
        )
    )
        + CALCULATE (
            SUM ( 'order'[current amount] ),
            FILTER ( 'order', SELECTEDVALUE ( 'date'[Date] ) > 'order'[inv paid] )
        )

    Best Regards,

    Zoe Zhi

     

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