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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
shirinshon
New Member

MTD calculation with condition

Hello,

 

I'm trying to calcualte MTD Earned Hours depending on the country. I have a table called Earned Hours Report which has columns such as site_ref, Standard Earned Hours etc. For example I want to calculate Earned Hours only for USA: Earned Hours MTD USA = IF ('EH Daily Report'[site_ref] = "USA", TOTALMTD( SUM('EH Daily Report'[Standard earned hours]),DimDate[Date], BLANK()), but it's not recognizing site_ref and gives an error. Could you please suggest how I can fix it?

 

shirinshon_0-1736874297992.png

shirinshon_1-1736874322902.png

shirinshon_2-1736874349079.png

 

2 ACCEPTED SOLUTIONS
rohit1991
Super User
Super User

Use this corrected DAX formula:

Key Fix:

  • Wrapped the condition 'EH Daily Report'[site_ref] = "USA" inside CALCULATE to apply it as a filter.
Earned Hours MTD USA = 
CALCULATE(
    TOTALMTD(SUM('EH Daily Report'[Standard earned hours]), DimDate[Date]),
    'EH Daily Report'[site_ref] = "USA"
)

 

View solution in original post

ToddChitt
Super User
Super User

Have you tried something like this to get just the USA component:

Earned Hours USA = CALCULATE (SUM ( [earnedHours] ), [Country] = "USA" )

Then using that in something like this:

MTD Earned Hours USA = TOTALMTD ( [Earned Hours USA], Dates[Date] )




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





View solution in original post

6 REPLIES 6
ToddChitt
Super User
Super User

Have you tried something like this to get just the USA component:

Earned Hours USA = CALCULATE (SUM ( [earnedHours] ), [Country] = "USA" )

Then using that in something like this:

MTD Earned Hours USA = TOTALMTD ( [Earned Hours USA], Dates[Date] )




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





rohit1991
Super User
Super User

Use this corrected DAX formula:

Key Fix:

  • Wrapped the condition 'EH Daily Report'[site_ref] = "USA" inside CALCULATE to apply it as a filter.
Earned Hours MTD USA = 
CALCULATE(
    TOTALMTD(SUM('EH Daily Report'[Standard earned hours]), DimDate[Date]),
    'EH Daily Report'[site_ref] = "USA"
)

 

Glad that corrected DAX works. But just know this: If you use that measure for, say, another country, it will still give you the USA results. Try this: Start a new, blan page. Add a Date slicer and select a date segment, like the current month. Create a simple Table visual and add the column

'EH Daily Report'[site_ref]' to it. Now add the [Earned Hours MTD USA] to the table.

It probably has the same value for every distinct value of [site_ref]! 

Are you absolutely sure that is what you want? Or would you rather let the context of the visual do the segregating for you?




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Hi ToddChitt

 

I tried applying it to different sites and it seems it worked (please see below). It's not the best way for me to build the report as I have to create a measure for each site now instead of using a slicer as an example where i would change the site and it would update the visual. 

 

shirinshon_0-1736883388936.png

 

What's the problem you are trying to solve? What is the ultimate end goal for the visual? Can you supply a mock-up, or describe it? (Screenshots are best, we all like pictures.)




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





So I have 4 tables in my BI report (Earned hours, Targets, Shipments and DimDate). Earned hours report is pulling data from sql server as Shipments table does and they are getting refreshed automatically. Targets table I created in Excel first and then loaded it in BI. It's needed to see targets for the month (shipmets and earned hours targets). Please see the relationship between tables below

shirinshon_1-1736885758254.png

This is Targets table and I tried to create a column "Site" but then i would have to repeat dates for example "1/1/2025 3 times because I have 3 sites. And it gives an error as the relationship becomes Many to Many between Targets and EH Daily report tables and Targets and Daily Shipment tables. So I couldnt resolve it. 

 

shirinshon_0-1736885646927.png

This is my visual for Shipments tab. I have a Daily visual (at the top) and MTD (bottom one). This is built only for USA site. My idea was to add a Slicer for "Site" but i still haven't fugire it out.

shirinshon_2-1736885917443.png

 

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 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors
Top Kudoed Authors