Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Fabric Community site will be in read-only mode on Monday, Feb 24 from 12:01 AM to 8 AM PST for scheduled upgrades.

Reply
SuzieKidd
Frequent Visitor

Costs for the days open in a month

Hi, I'm trying to work out how to calculate costs that were open for say 14 days in august and 25 days in september, how do I show the total monthly cost for the days open in august and september in power bi.  I have 2 tables, I have created a start date check so that if the costs started before 1st April 2023 then show that date else the actual start date, and I have another condtional column to check for the end date, so if the end is blank then show me 31st March 2024 else the atucal end date, and the start check date has a relationship with my calendar table date.

Thank you

7 REPLIES 7
gmsamborn
Super User
Super User

Hi @SuzieKidd 

 

My numbers seem to be off from yours so I added 'Date'[Date] to the columns after Month.

 

Click on the matrix.
Set "Drill on" to Columns.
Right-click on AUG.

Drill Down

 

This will show the daily detail for AUG.

 

You say that the range of AUG 5th to AUG 10th is 5 days whereas my count is 6 days.

 

Either the Start Date or the End Date would have to be ignored to match your numbers.

 



Proud to be a Super User!

daxformatter.com makes life EASIER!
Greg_Deckler
Super User
Super User

@SuzieKidd Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

Thank you for getting back to me, here is sample data in my Power BI Table

Customer IDCost IDStart DateEnd DateDays OpenDaily CostWeekly CostTotal Cost
1238568905/08/202410/08/20245£459.36£3,215.52£2,296.80
1239652311/08/2024 234£45.77£320.39£10,710.18
2351125301/04/202431/03/2025365£79.57£556.99£29,122.62
2372659801/04/202417/10/2024159£34.54£241.75£5,491.18
2374112518/10/202431/03/2025165£35.77£250.39£5,902.05
2356889501/04/2024 366£262.38£1,836.64£96,030.02

 

Where the costs started before the financial year start, I have changed the date to 1st April 2024 otherwise it's just the start date, where the cost is still open at the financial year end, I have changed the date to 31st March 2025 otherwise it's just the end date. What I need to see is the costs for each month that the costs was open for, so where the cost is open for 5 days in August I want to see £2296.80, where a cost is open for the whole financial year I want to see the cost for that month so 30 days in Apr, Jun, Sep and Nov and 31 days for the rest

Customer IDCost IDAprMayJunJulAugSepOctNov
12385689    £2296.80   
12396523    £9187.20£13780.80£14240.16£13780.80
23511253£2387.10£2466.67£2387.10£2466.67£2466.67£2387.10£2466.67£2387.10
23726598£1036.20£1070.74£1036.20£1070.74£1070.74£1036.20£1070.74 
23741125      £465.01£1036.20
23568895£7871.40£8133.78£7871.40£8133.78£8133.78£7871.40£8133.78£7871.40

 

I hope this makes sense.

Thank You

Suzie

Hi @SuzieKidd 

 

Would a measure like this help?

gmsamborn_0-1739835554962.png

 

Period Cost = 
VAR _CostStartDate = 
    CALCULATE( 
        MIN( 'FactTable'[Start Date] ), 
        ALL( 'Date' ) 
    )
VAR _CostEndDate = 
    COALESCE(
        CALCULATE( 
            MAX( 'FactTable'[End Date] ), 
            ALL( 'Date' ) 
        ),
        MAX( 'Date'[Date] )
    )
VAR _DailyCost = 
    CALCULATE( 
        MAX( 'FactTable'[Daily Cost] ), 
        ALL( 'Date' ) 
    )
VAR _Result = 
    SUMX(
        FILTER(
            'Date',
            'Date'[Date] >= _CostStartDate
                && 'Date'[Date] <= _CostEndDate
        ),
        _DailyCost
    )
RETURN
    _Result

 

 

 

Let me know if you have any questions.

 

(I forgot to mention I created a Customer dimension table iin Power Query.  It ended up not being required.  I also used a date table that has Fiscal Periods.)

 

open days.pbix



Proud to be a Super User!

daxformatter.com makes life EASIER!

Thank for you for getting back to me, sorry I may be being a bit dense but what is 'Date' in ALL, is this calendar date?  I'm unable to access the pbix access is blocked.

Hi @SuzieKidd 

 

The date in ALL() is from a date table.

 

Does you company block downloads?



Proud to be a Super User!

daxformatter.com makes life EASIER!

Thank you. 

 

Yes looks like they do block downloads.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.