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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
AlpanaSi
Frequent Visitor

How to retrieve last date non-zero value for each category

Hello

 

I am trying to resolve a problem since long. Below is a table with sub-categories like revenue from X, Y,...Product. Targets are set progressively over future time period for the product to achieve this revenue... here it is for next 3 years (2022-2024). As the time progresses, actual value will be entered. For this scenario, lets consider we are currently in 2023 and all the actual achieved value till 2023 will be entered and beyond that it is 0 because it lies in the future years and will entered subsequently as the time progress. 

 

Given the content, what I want is to build a gauge meter, line chart and KPI card.

On gauge meter, I want to show actual value, target value and planned value. E.g. for Revenue from X Product - Actual value = 11.32, Target value = 13.32 and Planned Value = 40

 

Similarly, on line chart I want to show line charts of Actual and Target, wherein target will be shown for all dates and actual will be shown for only those dates where value is not 0

 

KPI Card should return the value of actual, target and planned in one card.

 

The help that I need is writing code in how to return last date values (both actual and target) for each sub-category and return non-zero values for actual. Please note, the actual and target values might not be always in increasing order in real business scenario, so max function will not work here.

 

Please help in writing code for the same.   

 

 

CategorySub-CateogoryDateTargetActual
FinancialsRevenue from X Product11/1/202200
FinancialsRevenue from X Product11/1/202313.3211.32
FinancialsRevenue from X Product11/1/202426.680
FinancialsRevenue from X Product11/1/2025400
FinancialsRevenue from X Product11/1/20221210
FinancialsRevenue from Y Product2/1/202313.3411.34
FinancialsRevenue from Y Product5/1/202314.6412.64
FinancialsRevenue from Y Product8/1/202315.9913.99
FinancialsRevenue from Y Product11/1/202317.3315.33
FinancialsRevenue from Y Product2/1/202418.670
FinancialsRevenue from Y Product5/1/202419.990
FinancialsRevenue from Y Product8/1/202421.330
FinancialsRevenue from Y Product11/1/202422.670
FinancialsRevenue from Y Product3/1/202524.420
FinancialsRevenue from Y Product6/1/202525.770
FinancialsRevenue from Y Product9/1/202527.110
FinancialsRevenue from Y Product12/1/202528.440

 

Thanks

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @AlpanaSi 

Thanks for reaching out to us.

You can try these measures,

Actual_X = 
var _sub="Revenue from X Product"
var _year=2023 //lets consider we are currently in 2023 and all the actual achieved value till 2023 will be entered and beyond that it is 0
return CALCULATE(MAX('Table'[Actual]),FILTER(ALL('Table'),'Table'[Sub-Cateogory]=_sub && 'Table'[Date].[Year]=_year))
Target_X = 
var _sub="Revenue from X Product"
var _year=2023 //lets consider we are currently in 2023 and all the actual achieved value till 2023 will be entered and beyond that it is 0
return CALCULATE(MAX('Table'[Target]),FILTER(ALL('Table'),'Table'[Sub-Cateogory]=_sub && 'Table'[Date].[Year]=_year))
Planned_X = 
var _sub="Revenue from X Product"
var _maxDate=MAXX(FILTER(ALL('Table'),'Table'[Sub-Cateogory]=_sub),[Date])
return CALCULATE(MAX('Table'[Target]),FILTER(ALL('Table'),'Table'[Sub-Cateogory]=_sub && 'Table'[Date]=_maxDate))

vxiaotang_0-1661332079354.png

 

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

3 REPLIES 3
v-xiaotang
Community Support
Community Support

Hi @AlpanaSi 

Thanks for reaching out to us.

You can try these measures,

Actual_X = 
var _sub="Revenue from X Product"
var _year=2023 //lets consider we are currently in 2023 and all the actual achieved value till 2023 will be entered and beyond that it is 0
return CALCULATE(MAX('Table'[Actual]),FILTER(ALL('Table'),'Table'[Sub-Cateogory]=_sub && 'Table'[Date].[Year]=_year))
Target_X = 
var _sub="Revenue from X Product"
var _year=2023 //lets consider we are currently in 2023 and all the actual achieved value till 2023 will be entered and beyond that it is 0
return CALCULATE(MAX('Table'[Target]),FILTER(ALL('Table'),'Table'[Sub-Cateogory]=_sub && 'Table'[Date].[Year]=_year))
Planned_X = 
var _sub="Revenue from X Product"
var _maxDate=MAXX(FILTER(ALL('Table'),'Table'[Sub-Cateogory]=_sub),[Date])
return CALCULATE(MAX('Table'[Target]),FILTER(ALL('Table'),'Table'[Sub-Cateogory]=_sub && 'Table'[Date]=_maxDate))

vxiaotang_0-1661332079354.png

 

 

Best Regards,

Community Support Team _Tang

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

nvprasad
Solution Sage
Solution Sage

Hi AlpanaSi,

Cand you try with below DAX?

Target NonZero LatestDt = CALCULATE(MAX('Table'[Date]),ALLEXCEPT('Table','Table'[Subcategory]),'Table'[Target]>0)
Actual NonZero LatestDt = CALCULATE(MAX('Table'[Date]),ALLEXCEPT('Table','Table'[Subcategory]),'Table'[Actual]>0)

 

nvprasad_0-1660730094355.png

Appreciate a Kudos! ‌‌
If this helps and resolves the issue, please mark it as a Solution! ‌‌

Regards,
N V Durga Prasad

Hello @nvprasad 

 

I dont want to retrieve the last date, instead retreive non-zero actual and target values corresponding to last date. For e.g.

For Revenue from X Product, Actual value = 11.32, Target value = 13.32 and Planned Value = 40. I want to use these values to build gauge meter and KPI card for each subcategory. 

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.