Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

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
Microsoft Employee
Microsoft 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
Microsoft Employee
Microsoft 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
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.