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
Anonymous
Not applicable

Find Difference (Substract) between dates which are in same column in the Table

I have souce table as below and i want output shown in image2.

As user want to see the difference of any two dates that is available in the source, so Please help me if there is any dynamic way to do this?

 

Source table:

CountryReceived_Date (wk)Amount
IND2/5/2019100
IND2/5/2019150
AUS2/5/2019120
AUS2/5/2019180
CN2/5/2019200
CN2/5/201990
IND2/12/2019180
IND2/12/2019345
AUS2/12/2019234
AUS2/12/2019566
CN2/12/2019123
CN2/12/2019575
IND2/19/201934
IND2/19/2019687
AUS2/19/201956
AUS2/19/2019534
CN2/19/201979
CN2/19/201923

 

image2 (output in power bi):

Country2/5/20192/12/2019Diff
AUS300800500
CN290698408
IND250525

275

 

OR (user selects the dates that he want to see Diff)

 

Country2/12/20192/19/2019Diff
AUS800590-210
CN698102-596
IND525721196

 

Note: i receive data every week and the received date will be in the source table.

1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @Anonymous 

 

You may create measures like below. Attached sample file for your reference.

Diff = 
VAR Max_Date =
    MAXX ( ALLSELECTED ( Table3 ), Table3[Received_Date (wk)] )
VAR Min_Date =
    MINX ( ALLSELECTED ( Table3 ), Table3[Received_Date (wk)] )
RETURN
    CALCULATE ( SUM ( Table3[Amount] ), Table3[Received_Date (wk)] = Max_Date )
        - CALCULATE ( SUM ( Table3[Amount] ), Table3[Received_Date (wk)] = Min_Date )
Measure = 
IF (
    SUM ( Table3[Amount] ) = SUMX ( ALLSELECTED ( Table3 ), Table3[Amount] )
        || SUM ( Table3[Amount] )
            = SUMX (
                FILTER ( ALLSELECTED ( Table3 ), Table3[Country] = MAX ( Table3[Country] ) ),
                Table3[Amount]
            ),
    [Diff],
    SUM ( Table3[Amount] )
)

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-cherch-msft
Employee
Employee

Hi @Anonymous 

 

You may create measures like below. Attached sample file for your reference.

Diff = 
VAR Max_Date =
    MAXX ( ALLSELECTED ( Table3 ), Table3[Received_Date (wk)] )
VAR Min_Date =
    MINX ( ALLSELECTED ( Table3 ), Table3[Received_Date (wk)] )
RETURN
    CALCULATE ( SUM ( Table3[Amount] ), Table3[Received_Date (wk)] = Max_Date )
        - CALCULATE ( SUM ( Table3[Amount] ), Table3[Received_Date (wk)] = Min_Date )
Measure = 
IF (
    SUM ( Table3[Amount] ) = SUMX ( ALLSELECTED ( Table3 ), Table3[Amount] )
        || SUM ( Table3[Amount] )
            = SUMX (
                FILTER ( ALLSELECTED ( Table3 ), Table3[Country] = MAX ( Table3[Country] ) ),
                Table3[Amount]
            ),
    [Diff],
    SUM ( Table3[Amount] )
)

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

Top Solution Authors