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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.