cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
IsseBisse
Frequent Visitor

Monthly cost with monthly, quarterly and yearly limits

I have two tables:

Issues

CustomerDateCost
A2022-04-01100
A2022-05-04150
B2022-06-01200
.........

 

Limits

CustomerMonthlyQuarerlyYearly
A 150 
B100 500
............

 

I want to visualize costs per customer per month but capped by all limits. Something like this:

CustomerYear-MonthCost<comment>
A2022-04100 
A2022-0550Because of quarterly limit
A2022-060Regardless of actual cost, because quarterly limit is reached
...... ...
B2022-06100Because of monthly limit
...... ...

 

I've tried using a calculated table grouped by Customer and Year-Month, but I can't get the quarterly and yearly limits to work. Should I use a different approach (I saw someone suggest calculating daily costs then using measures)? What is the best approach?

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @IsseBisse ,

 

Here are the steps you can follow:

1. Create calculated table.

Cost =
var _table1=
DISTINCT('Issues'[Customer])
var _table2=
DISTINCT('Issues'[Date])
return
CROSSJOIN(_table1,_table2)

vyangliumsft_0-1685584595921.png

2. Create calculated column.

Issue =
SUMX(
    FILTER(ALL(Issues),   'Issues'[Customer]=EARLIER('Cost'[Customer])&&YEAR('Issues'[Date])=YEAR(EARLIER('Cost'[Date]))&&MONTH('Issues'[Date])=MONTH(EARLIER('Cost'[Date]))),
    [Cost])
Rank =
RANKX(FILTER(ALL('Cost'),
'Cost'[Customer]=EARLIER('Cost'[Customer])),[Date],,ASC)
Column 2 =
var _Monthly=
SUMX(
    FILTER(ALL(Limits),'Limits'[Customer]=EARLIER('Cost'[Customer])),[Monthly])
var _Quarely =
SUMX(
    FILTER(ALL(Limits),'Limits'[Customer]=EARLIER('Cost'[Customer])),[Quarerly])
var _Yearly =
SUMX(
    FILTER(ALL(Limits),'Limits'[Customer]=EARLIER('Cost'[Customer])),[Yearly])
var _if=
IF(
    _Monthly<>BLANK() &&[Issue]>_Monthly,
    _Monthly,
    IF(
        _Quarely<>BLANK()&&[Issue]>=_Quarely,
        [Issue]-SUMX(FILTER(ALL('Cost'),'Cost'[Customer]=EARLIER('Cost'[Customer])&&'Cost'[Rank]=EARLIER('Cost'[Rank])-1),[Issue]),
        IF(
            _Yearly<>BLANK()&&[Issue]>_Yearly,
            _Yearly,[Issue]
)))
return
IF(
    _if=BLANK(),0,_if)

3. Result:

vyangliumsft_1-1685584595923.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

This doesn't seem to be working correctly. For instance with a slightly large example:
Issues

CustomerDateCost
C2022-01-01    100
C2022-02-02150
C2022-03-03100
C2022-04-04100
C2022-05-05150
C2022-06-06100
C2022-07-08150
C2022-08-22100
C2022-09-10150
C2022-10-11200
C2022-11-01100
C2022-12-24150

Limits

CustomerMonthlyQuarterlyYearly
C100250600

I would expect the following

Results

CustomerYear-monthCostComment
C2022-01100 
C

2022-02

100Because of monthly
C2022-0350Because of quarterly
C2022-04100 
C2022-05100Because of monthly
C2022-0650Because of quarterly
C2022-07100Because of monthly
C2022-080Because of yearly
C2022-090 Because of yearly
 ...... 

 

But instead I get
Cost

CustomerDateSum of Column 2

C2022-01-01 00:00    100
C2022-02-02 00:00100
C2022-03-03 00:00100
C2022-04-01 00:00100
C2022-04-04 00:00100
C2022-05-04 00:00100
C2022-05-05 00:00100
C2022-06-01 00:00100
C2022-06-06 00:00100
C2022-07-08 00:00100
C2022-08-22 00:00100
C2022-09-10 00:00100
C2022-10-11 00:00100
C2022-11-01 00:00100
C2022-12-24 00:00100

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors