Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi All,
I want to show Previous month sales values in Card for KPI use. I want values like below.
suppose my sales date table is present till 06 March 2024 and sales from 1st march to 03 march sales revenue is 120
Now I want to see only sales revenue for previous month from 1st Feb'24 to 03 Feb only.
Below is sample data for your refernce.
Expected ouptut from below table would be like below
Current Month Total_Count =114 ( Date 1st Mar To 3rd Mar)
Previous month Total_Count =140 (Date from 1st feb to 3rd feb)
| INSERT_DT | Year | Quarter | Month | Day | Total_Count |
| 1-Jan-24 | 2024 | Qtr 1 | January | 1 | 30 |
| 2-Jan-24 | 2024 | Qtr 1 | January | 2 | 45 |
| 3-Jan-24 | 2024 | Qtr 1 | January | 3 | 50 |
| 4-Jan-24 | 2024 | Qtr 1 | January | 4 | 53 |
| 5-Jan-24 | 2024 | Qtr 1 | January | 5 | 51 |
| 6-Jan-24 | 2024 | Qtr 1 | January | 6 | 49 |
| 7-Jan-24 | 2024 | Qtr 1 | January | 7 | 31 |
| 8-Jan-24 | 2024 | Qtr 1 | January | 8 | 52 |
| 9-Jan-24 | 2024 | Qtr 1 | January | 9 | 55 |
| 10-Jan-24 | 2024 | Qtr 1 | January | 10 | 54 |
| 11-Jan-24 | 2024 | Qtr 1 | January | 11 | 57 |
| 12-Jan-24 | 2024 | Qtr 1 | January | 12 | 54 |
| 13-Jan-24 | 2024 | Qtr 1 | January | 13 | 35 |
| 14-Jan-24 | 2024 | Qtr 1 | January | 14 | 30 |
| 15-Jan-24 | 2024 | Qtr 1 | January | 15 | 42 |
| 16-Jan-24 | 2024 | Qtr 1 | January | 16 | 45 |
| 17-Jan-24 | 2024 | Qtr 1 | January | 17 | 47 |
| 18-Jan-24 | 2024 | Qtr 1 | January | 18 | 46 |
| 19-Jan-24 | 2024 | Qtr 1 | January | 19 | 46 |
| 20-Jan-24 | 2024 | Qtr 1 | January | 20 | 44 |
| 21-Jan-24 | 2024 | Qtr 1 | January | 21 | 27 |
| 22-Jan-24 | 2024 | Qtr 1 | January | 22 | 37 |
| 23-Jan-24 | 2024 | Qtr 1 | January | 23 | 43 |
| 24-Jan-24 | 2024 | Qtr 1 | January | 24 | 44 |
| 25-Jan-24 | 2024 | Qtr 1 | January | 25 | 43 |
| 26-Jan-24 | 2024 | Qtr 1 | January | 26 | 24 |
| 27-Jan-24 | 2024 | Qtr 1 | January | 27 | 32 |
| 28-Jan-24 | 2024 | Qtr 1 | January | 28 | 24 |
| 29-Jan-24 | 2024 | Qtr 1 | January | 29 | 42 |
| 30-Jan-24 | 2024 | Qtr 1 | January | 30 | 43 |
| 31-Jan-24 | 2024 | Qtr 1 | January | 31 | 40 |
| 1-Feb-24 | 2024 | Qtr 1 | February | 1 | 53 |
| 2-Feb-24 | 2024 | Qtr 1 | February | 2 | 45 |
| 3-Feb-24 | 2024 | Qtr 1 | February | 3 | 42 |
| 4-Feb-24 | 2024 | Qtr 1 | February | 4 | 24 |
| 5-Feb-24 | 2024 | Qtr 1 | February | 5 | 49 |
| 6-Feb-24 | 2024 | Qtr 1 | February | 6 | 47 |
| 7-Feb-24 | 2024 | Qtr 1 | February | 7 | 46 |
| 8-Feb-24 | 2024 | Qtr 1 | February | 8 | 47 |
| 9-Feb-24 | 2024 | Qtr 1 | February | 9 | 44 |
| 10-Feb-24 | 2024 | Qtr 1 | February | 10 | 31 |
| 11-Feb-24 | 2024 | Qtr 1 | February | 11 | 23 |
| 12-Feb-24 | 2024 | Qtr 1 | February | 12 | 45 |
| 13-Feb-24 | 2024 | Qtr 1 | February | 13 | 51 |
| 14-Feb-24 | 2024 | Qtr 1 | February | 14 | 45 |
| 15-Feb-24 | 2024 | Qtr 1 | February | 15 | 47 |
| 16-Feb-24 | 2024 | Qtr 1 | February | 16 | 49 |
| 17-Feb-24 | 2024 | Qtr 1 | February | 17 | 45 |
| 18-Feb-24 | 2024 | Qtr 1 | February | 18 | 25 |
| 19-Feb-24 | 2024 | Qtr 1 | February | 19 | 44 |
| 20-Feb-24 | 2024 | Qtr 1 | February | 20 | 47 |
| 21-Feb-24 | 2024 | Qtr 1 | February | 21 | 45 |
| 22-Feb-24 | 2024 | Qtr 1 | February | 22 | 49 |
| 23-Feb-24 | 2024 | Qtr 1 | February | 23 | 45 |
| 24-Feb-24 | 2024 | Qtr 1 | February | 24 | 40 |
| 25-Feb-24 | 2024 | Qtr 1 | February | 25 | 27 |
| 26-Feb-24 | 2024 | Qtr 1 | February | 26 | 44 |
| 27-Feb-24 | 2024 | Qtr 1 | February | 27 | 45 |
| 28-Feb-24 | 2024 | Qtr 1 | February | 28 | 46 |
| 29-Feb-24 | 2024 | Qtr 1 | February | 29 | 45 |
| 1-Mar-24 | 2024 | Qtr 1 | March | 1 | 45 |
| 2-Mar-24 | 2024 | Qtr 1 | March | 2 | 42 |
| 3-Mar-24 | 2024 | Qtr 1 | March | 3 | 27 |
Solved! Go to Solution.
Hi @Sandeep13 ,
Please try below steps:
1. below is my test table
Table:
2. create measure with below dax formula
Current Month Total_Count =
VAR max_date =
MAX ( 'Table'[INSERT_DT] )
VAR _month =
MONTH ( max_date )
VAR tmp =
FILTER (
ALL ( 'Table' ),
[INSERT_DT] <= max_date
&& MONTH ( [INSERT_DT] ) = _month
)
RETURN
SUMX ( tmp, [Total_Count] )
Previous month Total_Count =
VAR max_date =
MAX ( 'Table'[INSERT_DT] )
VAR tmp =
FILTER (
ALL ( 'Table' ),
MONTH ( [INSERT_DT] ) = MONTH ( max_date )
&& YEAR ( 'Table'[INSERT_DT] ) = YEAR ( max_date )
)
VAR min_date =
MINX ( tmp, [INSERT_DT] )
VAR _a =
CALCULATE (
MAX ( 'Table'[INSERT_DT] ),
DATEDIFF ( 'Table'[INSERT_DT], min_date, DAY ) = 29
)
VAR _b =
CALCULATE (
MAX ( 'Table'[INSERT_DT] ),
DATEDIFF ( 'Table'[INSERT_DT], max_date, DAY ) = 29
)
VAR tmp1 =
FILTER ( ALL ( 'Table' ), [INSERT_DT] >= _a && [INSERT_DT] <= _b )
RETURN
SUMX ( tmp1, [Total_Count] )
3. add two card visual with measure
Please refer the attached .pbix file.
Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Sandeep13 ,
Please try below steps:
1. below is my test table
Table:
2. create measure with below dax formula
Current Month Total_Count =
VAR max_date =
MAX ( 'Table'[INSERT_DT] )
VAR _month =
MONTH ( max_date )
VAR tmp =
FILTER (
ALL ( 'Table' ),
[INSERT_DT] <= max_date
&& MONTH ( [INSERT_DT] ) = _month
)
RETURN
SUMX ( tmp, [Total_Count] )
Previous month Total_Count =
VAR max_date =
MAX ( 'Table'[INSERT_DT] )
VAR tmp =
FILTER (
ALL ( 'Table' ),
MONTH ( [INSERT_DT] ) = MONTH ( max_date )
&& YEAR ( 'Table'[INSERT_DT] ) = YEAR ( max_date )
)
VAR min_date =
MINX ( tmp, [INSERT_DT] )
VAR _a =
CALCULATE (
MAX ( 'Table'[INSERT_DT] ),
DATEDIFF ( 'Table'[INSERT_DT], min_date, DAY ) = 29
)
VAR _b =
CALCULATE (
MAX ( 'Table'[INSERT_DT] ),
DATEDIFF ( 'Table'[INSERT_DT], max_date, DAY ) = 29
)
VAR tmp1 =
FILTER ( ALL ( 'Table' ), [INSERT_DT] >= _a && [INSERT_DT] <= _b )
RETURN
SUMX ( tmp1, [Total_Count] )
3. add two card visual with measure
Please refer the attached .pbix file.
Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Bro its worked for me. THANKS A TON😊
Just one query why you are using 29 in variable condition ?
Hi Sandeep,
you can try with:
SPLMonth =
CALCULATE (
SUM ( total_count ), -- in general your basic measure
FILTER (
ALL ( fact, column date),
column_date >= DATE ( YEAR(TODAY()), MONTH(TODAY())-1,1) && column_date <= TODAY()
)
)
Let me know if it is OK.
Hi @Mattiar,
Output is not showing as expected ,
Previous month should be Total_Count =140 of (1st Feb to 3rd feb) is what i want to show.
Below SS for your reference.
Right, one more condition is missing because if not, it goes up to today.
In the second part replace:
&& column_date <= TODAY()
with
&& DATE ( YEAR(TODAY()), MONTH(TODAY())-1, DAY ( TODAY()))
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 38 | |
| 36 | |
| 33 | |
| 30 | |
| 28 |
| User | Count |
|---|---|
| 128 | |
| 88 | |
| 79 | |
| 67 | |
| 62 |