Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello there,
I am trying to subtract values of a single column from different dates.
I have created a column (Red Date) which is the current date less 3 months.
Now I want to subtract values from the Red Date from the values at the Main Date.
Acumm(104days) = CALCULATE(
VAR _CurrentCumCases = SUM(Sheet1[Cummulative Cases])
VAR _OldCumCases =CALCULATE(
SUM(Sheet1[Cummulative Cases]),FILTER(Sheet1,Sheet1[Date] = Sheet1[RedDate])
)
VAR Red_Population = _CurrentCumCases - _OldCumCases
RETURN
Red_Population
)
At the moment if I return _OldCumCases I get null values and not sure why.
Thanks in advance
Hi @Anonymous -
FILTER(Sheet1,Sheet1[Date] = Sheet1[RedDate])
FILTER is a table iterator, so you're basically saying "give me all records where Date = Red Date", which is going to be 0 records every time.
Try something like this (not tested since I don't have your data). You basically need to build a date table that is 3 months shifted from the current one.
Acumm(104days) = CALCULATE(
VAR _CurrentCumCases = SUM(Sheet1[Cummulative Cases])
VAR _OldCumCases = CALCULATE(
SUM(Sheet1[Cummulative Cases]),
DATESBETWEEN( DATEADD ( MIN(Sheet1[Date]) ), -3, MONTH ),
DATEADD ( MAX(Sheet1[Date]) ), -3, MONTH )
)
VAR Red_Population = _CurrentCumCases - _OldCumCases
RETURN
Red_Population
)
In all honesty this may not work as you want without a calendar table if your Sheet1 doesn't have all consecutive dates. If this doesn't help, please give as much information as you can (sample report with sensitive data removed is always best) and we'll see if we can get you where you need to go.
Hope this helps
David
User | Count |
---|---|
25 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
30 | |
13 | |
11 | |
9 | |
6 |