Forum Discussion
PREVIOUSMONTH Query
Hi,
Is it possible to calculate the volume of cases that are over 3 years old as it was a month ago using PREVIOUSMONTH or DATEADD?
This measure calculates the number of Cases that are 3 years or older as at NOW =
# Cases 3 Yrs or Older =
CALCULATE(
COUNTROWS(FILTER('Cases',
'Cases'[Case Length] > 1095)),
'Cases'[statecode] = "Active")
'Cases' [Case Length] is a calculated column =
Case Length =
IF (
'Cases'[statecode] = "Active",
DATEDIFF ( 'Cases'[Created On], NOW (), DAY ),
DATEDIFF ( 'Cases'[Created On], 'Cases'[Resolution Date], DAY ))
I have tried the following measure but the result is blank, I have a feeling this isn't possible - can anyone help?
I've tried using the 'Created On' Date in the Cases Table and the Date2 Date that it is related to but neither works.
# Cases 3 Yrs or Older PM =
CALCULATE(
[# Cases 3 Yrs or Older],
PREVIOUSMONTH(Date2[Date]))
As you described, you want to achieve the same function as timestamp, which will not be possible in power bi. You can also understand the reason when you use power bi. It is a data display tool and does not provide data snapshot function. Since your status may be updated at any time, but the calculation logic of DAX is to filter out the data that meets your filter in the data you import, and then perform an aggregation.
So, if you want to achieve the timestamp function like Oracle database, then you can manually record it in excel in the monthly email subscription you mentioned. The report provides a "month-end" snapshot of our transaction volume and total at 2359 o'clock on the last day of each month.hackcrr
If I have answered your question, please mark my reply as solution and kudos to this post, thank you!
12 Replies
- rajendraongole1Super User
Hi ArchStanton - create a measure that shifts the calculation context back by one month, hope you already have a date table as per above reference.
# Cases 3 Yrs or Older PM =
CALCULATE(
COUNTROWS(
FILTER(
'Cases',
'Cases'[Case Length] > 1095
)
),
'Cases'[statecode] = "Active",
DATEADD(Date2[Date], -1, MONTH)
)Try the above. Hope it works.
- ArchStantonPower Participant
Thanks - well its calculating something other than a BLANK now!
The figure I'm getting is ~300 but the correct figure should be ~1,100.As per the measure you've provided, I'm trying to calculate the number of Cases that were over 1095 days old a month ago. The live Dynamics system that I'm connected to doesn't timestamp or provide snapshots of data at a point in time - so is it even possible to use my Date2 calendar -1 MONTH to calculate how many cases were >1095 days old last month?
Cases Created on date has a many to one to Date2 Date.
- rajendraongole1Super User
Hi ArchStanton - Can you try the below modified measure. This ensures you’re looking at the cases as of the last day of the previous month. hope this works. still issue exist, please share sample data for reference.
Thank you
# Cases 3 Yrs or Older PM =
VAR EndOfPrevMonth = EOMONTH(MAX(Date2[Date]), -1)
RETURN
CALCULATE(
COUNTROWS(
FILTER(
'Cases',
'Cases'[Created On] <= EndOfPrevMonth - 1095 &&
(
('Cases'[statecode] = "Active" &&
DATEDIFF('Cases'[Created On], EndOfPrevMonth, DAY) > 1095)
||
('Cases'[statecode] <> "Active" &&
'Cases'[Resolution Date] <= EndOfPrevMonth &&
DATEDIFF('Cases'[Created On], 'Cases'[Resolution Date], DAY) > 1095)
)
)
)
)
- Ritaf1983Super User
Hi ArchStanton
Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.
How to Get Your Question Answered Quickly
- ArchStantonPower Participant
Hi,
Thanks for your reply.
I've had a possible solution from a SuperUser that produces a result other than BLANK for the first time so we may be getting somewhere at last.
Can you have a look at my response to his solution and see if this is at all possible please?Unfortunately I cannot share a pbix file for sommercial sensitivity reasons, the data model is huge and very complex so even producing a dummy file would take some time. If you think the other response is invalid and think its worthwhile, I'll try and create a dummy pbix file when I get some time.
Thanks,
- Ritaf1983Super User
Hi ArchStanton
Hi, I apologize, but in most cases, I really can't fully understand the request until I 'touch' the data myself. If the person who started working on it doesn't assist, I'll try to help once you attach the file.
- hackcrrMemorable Member
Hi, ArchStanton
You can try the following DAX expression:
# Cases 3 Yrs or Older PM = VAR SelectedDate = MAX(Date2[Date]) VAR PreviousMonthDate = EOMONTH(SelectedDate, -1) VAR ThresholdDate = PreviousMonthDate - 1095 RETURN CALCULATE( COUNTROWS( FILTER( 'Cases', 'Cases'[Created On] >= ThresholdDate && 'Cases'[Case Length] > 1095 && 'Cases'[statecode] = "Active" ) ), PREVIOUSMONTH(Date2[Date]) )I will use max to return the date in the date2 table, then use Emonth to return the last day of the previous month, and then calculate the day three years ago through ThresholdDate. Then filter the rows that fall within these date ranges in Filter.
hackcrr
If I have answered your question, please mark my reply as solution and kudos to this post, thank you!
- ArchStantonPower Participant
Hi,
No error message but unfortynately your measure does not return any values:
- hackcrrMemorable Member
This DAX depends on your current context and you need to adjust it appropriately for your situation. As you can see, it works well in the example I created because my simple dataset can run it. If your dataset is more complex, it will appear as shown in the picture.
hackcrr
If I have answered your question, please mark my reply as solution and kudos to this post, thank you!