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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

YTD vs last value

I have a table with the monthly cost and headcount at the end of the month

 

The table is set up like that:

Month | Amount | Type

Jan | 100 | Cost

Jan | 5 |  HC

Feb | 110  | Cost

Feb  | 6 | HC

Mar  | 130 | Cost

Mar | 8 |  HC

 

There is a filter Type with "HC" vs "Cost"

Using the time intelligence feature from Power BI, I get 340€ from Jan to Mar. Fine.

But if I select "HC" in the Type filter, I get of course 19 HC (the sum of all HC) when I expect to get the last value 8.

How can I achieve that?

 

Thanks for your help

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

Create three measures as shown below. The table is named CostAndHC, and is joined to the Date table. I converted the Month field to a date field (e.g., Jan becomes 1/1/20) in order to join to the date table. This approach assumes a date slicer is used.

 

EOM Cost =
CALCULATE (
TOTALYTD ( SUM ( CostAndHC[Amount] ), 'Date'[Date] ),
CostAndHC[Type] = "Cost"
)

 

EOM HC =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR MonthMaxDate =
MONTH ( MaxDate )
VAR YearMaxDate =
YEAR ( MaxDate )
VAR DateToFilter =
DATE ( YearMaxDate, MonthMaxDate, 1 )
RETURN
CALCULATE (
SUM ( CostAndHC[Amount] ),
CostAndHC[Type] = "HC",
CostAndHC[Date] = DateToFilter
)

 

EOM Amount =
VAR SelType =
SELECTEDVALUE ( CostAndHC[Type] )
RETURN
SWITCH ( SelType,
"Cost", [EOM Cost],
"HC", [EOM HC]
)

 

Then, create a matrix as shown below:

 

DataInsights_0-1593989947497.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @Anonymous ,

You can create a calculated column to get month number first, then create a measure to get the amount:

Month Number = SWITCH('Table'[Month],"Jan",1,"Feb",2,"Mar",3,"Apr",4,"May",5,"Jun",6,"Jul",7,"Aug",8,"Sep",9,"Oct",10,"Nov",11,"Dec",12)
Measure = 
VAR _maxMonth =
    CALCULATE (
        MAX ( 'Table'[Month Number] ),
        ALLEXCEPT ( 'Table', 'Table'[Type] )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[Type] ) = "HC",
   CALCULATE (
            MAX ( 'Table'[Amount] ),
            FILTER ( 'Table', 'Table'[Month Number] = _maxMonth )
        ),
        CALCULATE ( SUM ( 'Table'[Amount] ) )
    )

YTD vs last value.JPG

Best Regards

Rena

amitchandak
Super User
Super User

@Anonymous , Try a new measure like with time intelligence in case you have date

 

CALCULATE(SUM(costandhc[Amount]), DATESYTD('Date'[Date]),costandhc[Type] = "Cost")
+CALCULATE(lastnonblankvalue('Date'[Date],SUM(costandhc[Amount])),costandhc[Type] = "HC")

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Ashish_Mathur
Super User
Super User

Hi,

It is ideal to build a Calendar Table from the Month column, connect the 2 Tables and then use Date intelligence functions to fetch the HC as on the last date.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
DataInsights
Super User
Super User

Create three measures as shown below. The table is named CostAndHC, and is joined to the Date table. I converted the Month field to a date field (e.g., Jan becomes 1/1/20) in order to join to the date table. This approach assumes a date slicer is used.

 

EOM Cost =
CALCULATE (
TOTALYTD ( SUM ( CostAndHC[Amount] ), 'Date'[Date] ),
CostAndHC[Type] = "Cost"
)

 

EOM HC =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR MonthMaxDate =
MONTH ( MaxDate )
VAR YearMaxDate =
YEAR ( MaxDate )
VAR DateToFilter =
DATE ( YearMaxDate, MonthMaxDate, 1 )
RETURN
CALCULATE (
SUM ( CostAndHC[Amount] ),
CostAndHC[Type] = "HC",
CostAndHC[Date] = DateToFilter
)

 

EOM Amount =
VAR SelType =
SELECTEDVALUE ( CostAndHC[Type] )
RETURN
SWITCH ( SelType,
"Cost", [EOM Cost],
"HC", [EOM HC]
)

 

Then, create a matrix as shown below:

 

DataInsights_0-1593989947497.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thanks! It savess me hours!

 

Actually it was even simplier

Amount YTD Mix =
VAR SelType =
SELECTEDVALUE ('CoA'[Type] )
RETURN
SWITCH ( SelType,
"Cost (€)", [Amount YTD 2],
"Headcount", HR[Amount M],
"FTE", HR[Amount M]
)

 

with [Amount YTD 2] being the time intelligence Power BI generated field for YTD

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.