Forum Discussion
Measure to Count Records from Previous Month
Hello All,
I am trying to calculate the total records from the previous month.
I looked into a similar solution to my needs, but it did not help
https://community.powerbi.com/t5/Desktop/Create-a-measure-that-shows-me-the-previous-month/m-p/605919#M288486
All I want to do is create 2 CARDS
If my Slicer value is 01/01/2023, I want to see:
Card 1 = 4 (Current Month Count) (I can do this one)
Card 2 = 5 (Previous Month Count)
Table = Test1
| Report_Month | Job_Nbr |
| 1/01/2023 | 1251216 |
| 1/01/2023 | 1110997 |
| 1/01/2023 | 1044340 |
| 1/01/2023 | 1155551 |
| 1/12/2022 | 1048804 |
| 1/12/2022 | 1253120 |
| 1/12/2022 | 1290105 |
| 1/12/2022 | 1175991 |
| 1/12/2022 | 1285373 |
| 1/11/2022 | 1137240 |
I have also tried using these this measure as well
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Calc_Prev_Count =
Var Latest_M = MAX('Slicer_Month'[Report Month])
Var Current_Month_Count = CALCULATE(DISTINCTCOUNT('Test1'[Job_Nbr]),'Test1'[Report Month] = Latest_M)
Var Prvious_Month_Count = CALCULATE(DISTINCTCOUNT('Test1'[Job_Nbr]),'Test1'[Report Month] = EDATE(Latest_M,1))
Var Change_Value = 0 + Current_Month_Count - Prvious_Month_Count
Return Change_Value
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thankyou
Frank
2 Replies
- AnonymousNot applicable
Hello,
Please try using this format,
Prev Month Count=CALCULATE( COUNT('Table'[Column]), DATESYTD('Table'[Date]) = DATEADD(DATESYTD('Table'[Date]), -1, MONTH), SAMEPERIODLASTYEAR('Table'[Date]) )
Thanks,
- wollensackFrequent Visitor
Hello Sanika,
thankyou for replying to my message
I assumed your solution is only looking at the one table "Table1"
I tried your solution and got an errorPrev Month Count = CALCULATE( COUNT('Table1'[Order_Nbr]), DATESYTD('Table1'[Date]) = DATEADD(DATESYTD('Table1'[Date]), -1, MONTH), SAMEPERIODLASTYEAR('Table1'[Date]) )
Error = "A function 'DATESYTD' has been used in a True/False expression that is used as a table filter expression. This is not allowed."