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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
lucasvaranda
New Member

DAX

Hello everyone, I'm having a problem viewing my measurement on the card, which compares the current day to the previous day in percentages. I can see it normally on the graph and I can't see it on the card.

1: % preço = CALCULATE([Preço de venda](DATEADD(Calendario[Data].[Date], -1, DAY)))

2: var % preço = DIVIDE([Preço de venda] - [% preço], [% preço])
3: teste03 = FORMAT([var % preço]" ⬆ 0%; ⬇ 0%")

Screenshot_52.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @lucasvaranda ,

I create a table as you mentioned.

vyilongmsft_0-1715569638051.png

Then I create a measure and here is the DAX code.

SalePriceDifference = 
VAR _CurrentRowDate =
    MAX ( 'Table'[Date] )
VAR _PreviousRowDate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] < _CurrentRowDate )
    )
RETURN
    IF (
        _PreviousRowDate <> BLANK (),
        SUM ( 'Table'[Sale price] )
            - CALCULATE (
                SUM ( 'Table'[Sale price] ),
                FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] = _PreviousRowDate )
            )
    )

vyilongmsft_1-1715569738701.png

vyilongmsft_2-1715569838429.png

In Power BI Desktop, the card can only show one value, it doesn't show the values all together like a bar chart. It only show you the Total.

vyilongmsft_3-1715570126926.png

 

 

Best Regards

Yilong Zhou

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

2 REPLIES 2
Anonymous
Not applicable

Hi @lucasvaranda ,

I create a table as you mentioned.

vyilongmsft_0-1715569638051.png

Then I create a measure and here is the DAX code.

SalePriceDifference = 
VAR _CurrentRowDate =
    MAX ( 'Table'[Date] )
VAR _PreviousRowDate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] < _CurrentRowDate )
    )
RETURN
    IF (
        _PreviousRowDate <> BLANK (),
        SUM ( 'Table'[Sale price] )
            - CALCULATE (
                SUM ( 'Table'[Sale price] ),
                FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] = _PreviousRowDate )
            )
    )

vyilongmsft_1-1715569738701.png

vyilongmsft_2-1715569838429.png

In Power BI Desktop, the card can only show one value, it doesn't show the values all together like a bar chart. It only show you the Total.

vyilongmsft_3-1715570126926.png

 

 

Best Regards

Yilong Zhou

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

Greg_Deckler
Super User
Super User

@lucasvaranda See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
 ( __Current - __Previous ) * 1.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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