I have two tables called
- Main Table contains the following data(Pic) and
- Date table created using the dates from the Main table.
I want to calculate two fields/measures based on Date slicer selection from the Date Table
- current month's revenue
- previous month's revenue
Example: If I selected the 4th Month then it should sum distinct revenue of client A and B for the 4th month as current_month_revenue and Sum distinct revenue of A and B for 3rd month as previous_month_revenue.
I tried writing the following Measure to Calculate current_month_revenue and it is working fine but it is not giving the correct result for Previous_month_revenue. I am getting the same value for the Previous month as well.
'Measure Previous Month Revenue' =
IF (
ISFILTERED ( 'Date'[Year_Month] ),
VAR myTable =
SUMMARIZE (
'Main Table',
'Main Table'[ClientName],
'Main Table'[Mon],
'Main Table'[Revenue]
)
RETURN
CALCULATE (
SUMX (
myTable,
'Main Table'[Revenue]
),
FILTER (
'Main Table',
'Main Table'[Mon]
= SELECTEDVALUE ( 'Date'[Month] - 1 )
)
),
VAR myTable =
SUMMARIZE (
'Main Table',
'Main Table'[Revenue],
'Main Table'[Mon],
'Main Table'[Revenue]
)
RETURN
SUMX (
FILTER (
myTable,
'Main Table'[Mon]
= MONTH (
TODAY ()
) - 1
),
'Main Table'[Revenue]
)
)
Desired Output
If 4th month is selected
- Current Moth revenue = 100 + 200 = 300
- Previous Month = 100+200 = 300
In this case, both are the same but in actual data, revenue is different for each month.