Forum Discussion

PBIDEV_10's avatar
PBIDEV_10
Icon for Helper II rankHelper II
3 years ago

Total sum calculations based on year

Hi

I am working on a member dataset. Where the data is at date level. Data looks like:

MemberNo.Active flagDateFeePaidDateDifference in yearsPrice per year
111/1/202312/31/2022-1300
111/2/202312/31/2022-1300
111/3/202312/31/2022-1300
111/4/202312/31/2022-1300
111/5/202312/31/2022-1300
111/6/202312/31/2022-1300
111/7/202312/31/2022-1300
111/8/202312/31/2022-1300
211/1/202312/31/2022-1300
211/2/202312/31/2022-1300
211/3/202312/31/2022-1300
211/4/202312/31/2022-1300
211/5/202312/31/2022-1300
211/6/202312/31/2022-1300
211/7/202312/31/2022-1300
211/8/202312/31/2022-1300
1011/1/202312/31/2021-2300
1011/2/202312/31/2021-2300
1011/3/202312/31/2021-2300
1011/4/202312/31/2021-2300
1011/5/202312/31/2021-2300
1011/6/202312/31/2021-2300
1011/7/202312/31/2021-2300
1011/8/202312/31/2021-2300
1101/1/202312/31/2020-3300
1101/2/202312/31/2020-3300
1101/3/202312/31/2020-3300
1101/4/202312/31/2020-3300
1101/5/202312/31/2020-3300
1101/6/202312/31/2020-3300
1101/7/202312/31/2020-3300
1101/8/202312/31/2020-3300

Now I want to generate following matrices: 

 

Difference YearNo. of Inactive membersTotal sum to be paid
This year (0)  
Last year (-1)  
Last to last year (-2)  
More than 2 years (-3)1900

 

Difference YearNo. of Active membersTotal sum to be paid
This year (0)  
Last year (-1)2600
Last to last year (-2)1300
More than 2 years (-3)  

 

How can I achieve that with DAX? I tried to implement like this but gives wrong result:

 

Total sum to be paid = 
VAR DifferenceYear = CALCULATE(SUM(Fact_table[DifferenceYear]), LASTDATE(Date[Date]))
VAR PricePerYear = CALCULATE(SUM(Fact_table[PricePerYear]), LASTDATE(Date[Date]))
RETURN DifferenceYear * PricePerYear 

 

Regards

PGP

2 Replies