Forum Discussion

svinayagam1984's avatar
5 years ago
Solved

Need help with my measures

I need help with two things on my Power BI dashboard which I am building for my company   I have created four measures to report, New Customer # New Customer $ Lost Customer # Lost Customer $ ...
  • v-janeyg-msft's avatar
    v-janeyg-msft
    5 years ago

    Hi, svinayagam1984 

     

    I get it but the calculation is more complicated, because your needs are not suitable for multiple selection. If you want to do it, you need to create several virtual tables as var in the measure to calculate the previous week corresponding to the current week.

    Like this(example lost):

     

    flaglost = 
    VAR tab =
        ADDCOLUMNS (
            DISTINCT ( 'Date'[Date] ),
            "flag",
          
                VAR lastd =
                    CALCULATE (
                        MAX(  Data[Date]),
                        FILTER ( ALL ( Data ), [Date] <EARLIER ( 'Date'[Date] ) )
                    )
               
                VAR last =
                    CALCULATETABLE (
                        DISTINCT ( Data[Customer] ),
                        FILTER ( ALL ( Data ), [Date] = lastd )
                    )
                VAR cur =
                    CALCULATETABLE (
                        DISTINCT ( Data[Customer] ),
                        FILTER ( ALL ( Data ), [Date] = EARLIER ( 'Date'[Date] ) )
                    )
                RETURN
                    IF ( MAX ( Data[Customer] ) IN EXCEPT (last, cur ), 1, 0 )
        )
    RETURN
        IF ( SUMX ( tab, [flag] ) > 0, 1,0 )
    Measurelostamount = 
    VAR d =
        MINX ( FILTER ( Data, [flaglost] = 1 ), [Date] )
    RETURN
        SUMX ( FILTER ( Data, [flaglost] = 1 && [Date] = d ), [Amount] )
    Measurelost = 
    VAR tab =
        ADDCOLUMNS (
            DISTINCT ( 'Date'[Date] ),
            "flag",
                VAR lastd =
                    CALCULATE (
                        MAX ( Data[Date] ),
                        FILTER ( ALL ( Data ), [Date] < EARLIER ( 'Date'[Date] ) )
                    )
                VAR cur =
                    CALCULATETABLE (
                        DISTINCT ( Data[Customer] ),
                        FILTER ( ALL ( Data ), [Date] = EARLIER ( 'Date'[Date] ) )
                    )
                VAR last =
                    CALCULATETABLE (
                        DISTINCT ( Data[Customer] ),
                        FILTER ( ALL ( Data ), [Date] = lastd )
                    )
                RETURN
                    COUNTROWS ( EXCEPT ( last, cur ) )
        )
    RETURN
        SUMX ( tab, [flag] )

     

    Note: Don't create relationships in dates or you can create a single distinct table as slicer.

    If you still need help, please feel free to ask me.

     

    Best Regards

    Janey Guo

     

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