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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jmkvalsund
Helper II
Helper II

Measure showing running difference in table visual?

Hi,

does anyone know how to create a masure that shows the running difference of another column (which is a measure) in a table visual)?
I have a two measures like:


M_Sum_Sales =
SUM('tblSales'[SaleAmount])
M_Sum_Selected_Seller = CALCULATE('tblSales'[M_Sum_Sales] ,FILTER('tblSales','tblSales'[Seller]=[M_SelectedSeller]))+0
 
M_SelectedSeller comes from a slicer.

Each line in tblSales has a DateID, and M_Sum_Selected_Seller is calculated and grouped by DateID, so I get the selected seller's accumulated sales for each DateID, works fine.

Now, how can I add a column to the table visual that for each DateID calculates the difference between the current M_Sum_Selected_Seller and the M_Sum_Selected_Seller on the previous line (DateID)?  Thought this should be easy, but I don't get it. Tried using the EARLIER function, but that was not allowed. 
Anyone?
 
Regards,
John Martin



1 ACCEPTED SOLUTION

Hi @jmkvalsund ,
You can try this measure

Diff = 
VAR CurrentDate = MAX('Table'[DateID])
VAR PreviousDate = 
    CALCULATE(
        MAX('Table'[DateID]),
        FILTER(
            ALL('Table'),
            'Table'[DateID] < CurrentDate
        )
    )
VAR PreviousSale = 
    CALCULATE(
        SUM('Table'[SaleAmount]),
        'Table'[DateID] = PreviousDate
    )
RETURN
IF(
    ISBLANK(PreviousSale),
    0,
    SUM('Table'[SaleAmount]) - PreviousSale
)

Final output

vheqmsft_0-1724400276489.png

Best regards,
Albert He


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

5 REPLIES 5
jmkvalsund
Helper II
Helper II

@v-heq-msft    

Thanks a lot, works great!!

 

Regards,

John Martin

 

jmkvalsund
Helper II
Helper II

Hi @v-heq-msft ,

heres a fictive table created in Excel to show what I want to achieve. Data table to the left and the wanted output to the right.

jmkvalsund_2-1724396721344.png

 

 

Note:
The DateID is End-Of-Month for all previous months, since the Saleamount is accumulated by customerID (not shown here since it is not of importance). For current month, DateID is the latest update to PowerBI, typically two days before current date.

 

My headache is to create the column showing "Diff previous month".  Which is just the difference in M_Sum_Selected_Seller for each DateID.

 

Regards,

John Martin

 

Hi @jmkvalsund ,
You can try this measure

Diff = 
VAR CurrentDate = MAX('Table'[DateID])
VAR PreviousDate = 
    CALCULATE(
        MAX('Table'[DateID]),
        FILTER(
            ALL('Table'),
            'Table'[DateID] < CurrentDate
        )
    )
VAR PreviousSale = 
    CALCULATE(
        SUM('Table'[SaleAmount]),
        'Table'[DateID] = PreviousDate
    )
RETURN
IF(
    ISBLANK(PreviousSale),
    0,
    SUM('Table'[SaleAmount]) - PreviousSale
)

Final output

vheqmsft_0-1724400276489.png

Best regards,
Albert He


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

 

 

Hi @v-heq-msft ,

 

I'm feeling a bit stupid now, but could you show me how to create another measure which accumulates the values from Diff for each DateID? 

Regards,
John Martin

v-heq-msft
Community Support
Community Support

Hi @jmkvalsund ,

Can you provide some sample data? We can better understand the problem and help you.

How to provide sample data in the Power BI Forum - Microsoft Fabric Community

Or show it as a screenshot or pbix. Please remove any sensitive data in advance. If uploading pbix files please do not log into your account.


Best regards,
Albert He


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

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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