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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ali1234
Helper I
Helper I

DAX measure to find months of coverage and associated Cost

Hi,

 

I have a dataset with Service Call details. It provides information on System ID, date of service and associated costs (labor, material etc.). 

A second table has system coverage information. It also has System ID, Contract Name, start and end dates. Challenge is that each system may have 1 to n number of contracts often with overlapping periods as well as periods in between that had no coverage. So, one has to figure it out based on contract end and start dates.

 

As system IDs are repeated in both tables, I have created a list of unique SystemIds and linked it with both datasets. I also have a standard calendar table in my model. It is only linked to the first table of Service calls with date of Service. I could link the dates to start and end as well but i have been able to use the greater than or equal to function to create some of the measures using the coverage dates.

Here are the two measures I am looking to develop:

1. Contract_Coverage_Months: This is the count of number of months a given system (or group) has been under contract. It needs to exclude months without coverage and also not double count the months if more than 1 contract is in place during a given period. 

2. Contract_Spend: This is the sum of costs from the Service call's dataset for only the dates that fall within a contract coverage period. Service is often performed for systems outside the coverage period and those costs need to be excluded. 

4 REPLIES 4
Greg_Deckler
Super User
Super User

@ali1234 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.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler for the feedback..

I'll try again. Here's the table of data

Table Name: Svc_CallTbl

 

Asset_IDService Call #Service Call DateLabor CostMaterial CostTotal CostRegion
Asset123Call23403/03/2019$100$200$300Europe
Asset123Call34507/21/2019$50$75$125Europe
Asset345Call54302/02/2020$60$80$140Canada
Asset123Call65603/09/2020$20$25$45Europe
Asset123Call56510/1/2019$50$110$160Europe

 

The second table is for Contract information

Table Name: Contract_Tbl

Asset_ID Contract Name Contract Start Date Contract End Date
Asset123 Con Coverage1 01/01/2019 03/31/2019
Asset123 Con Coverage2 08/01/2019 07/31/2020
Asset123 Con Coverage3 10/01/2019 07/31/2020
Asset677 Con Coverage1 12/01/2019 12/31/2020

 

Asset_ID columns are linked in the data model. Also, date column of a standard calendar table is mapped to the Service Call Date column of the first table. I also have a list of unique Asset_IDs in a table that is linked to both the tables above.

 

Following measures are needed:

 

NumberOfCoverageMonths & Contract_Period_Costs

If Year 2019 is selected, then output would be as given in the table below. (Note: Asset123 cost is 460 which is the sum of costs incurred in March and October. Cost incurred in July is not included as no active period of contract exists in July)

Asset_ID NumberOfCoverageMonths Contract_Period_Costs
Asset123 08 460
Asset345 00 00
Asset677 01 00
Anonymous
Not applicable

Need some test data and a clear picture of what your input is and what the output should be. Please see this guide: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

Thanks @Anonymous , I have added additional information. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors