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
ciarano
Frequent Visitor

Current day sum vs previous day sum

Hi,

 

Very new to Power BI, so any help is appreciated.

 

I have a database table that has fields Category, SubCategory, Value and ReportDate. The Value is not a sales figure, it's a point-in-time valuation (think stock value on a given day). This gets populated every day, so I have rows with contiguous dates and the value changing each day.

 

I'm looking to make a table report that has Category, Value Today, Value 30 Days Ago and Value 90 Days Ago (these value columns need to be summed by category). Delta columns would be an added bonus. All the data required for something like this is in the table I think but I'm not sure how to approach it.

 

I have created a Date table (like here http://community.powerbi.com/t5/Desktop/how-to-calculate-month-over-month-sales/m-p/63647/highlight/...) hoping it would help but I'm not getting anywhere.

 

I've tried adding these measures to the report, but they are both the same value (and are also the same as just adding my [Value] column).

CurrentDayValue = CALCULATE(SUM(ValuationTable[Value]), DATEADD(DateTable[Date], 0, MONTH))

30DayValue = CALCULATE(SUM(ValuationTable[Value]), DATEADD(DateTable[Date], -30, DAY))

 

If I don't display my measures and just show [Category] and [Value] and add a filter on the ReportDate, I can see all my dates and selecting just 1 date results in a value I expect. I can also then just filter on a previous date and see the correct value for that date, but I want these to be side by side in the report.

 

Hope this makes sense. Can anyone help?

 

Cheers,
Ciaran

1 ACCEPTED SOLUTION
ciarano
Frequent Visitor

I think I have something that works.

Would be interested in hearing feedback if this is a good approach or if there's a better way:

 

Previous Value = 
CALCULATE (
    SUM (ValuationTable[Value]),
        FILTER (
            ALL (ValuationTable),
            COUNTROWS (
                FILTER (
                    ValuationTable,
                    EARLIER (ValuationTable[ReportDate]) = DATEADD(ValuationTable[ReportDate], -30, DAY)
                        && EARLIER (ValuationTable[Category]) = ValuationTable[Category]
                 )
            )
      )
)

View solution in original post

2 REPLIES 2
ciarano
Frequent Visitor

I think I have something that works.

Would be interested in hearing feedback if this is a good approach or if there's a better way:

 

Previous Value = 
CALCULATE (
    SUM (ValuationTable[Value]),
        FILTER (
            ALL (ValuationTable),
            COUNTROWS (
                FILTER (
                    ValuationTable,
                    EARLIER (ValuationTable[ReportDate]) = DATEADD(ValuationTable[ReportDate], -30, DAY)
                        && EARLIER (ValuationTable[Category]) = ValuationTable[Category]
                 )
            )
      )
)

Hi Ciarano,

 

I am having transaction amount, Status and date in my data. wanted to show the value with indicator showing green (if value is greater than previous day) or red (if it is lesser than previos day). Please help me on the same.

 

Thanks,

Anupam

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.