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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
alexandrem79
Frequent Visitor

Help! Calculate the distinct positions considering the last inspection in the month the vehicle

Hello all,

I need help, I'm not able to calculate the distinct positions considering the last inspection of the vehicle in the month.

 

TABLE:

FleetPositionDateValue
Fleet1    695475-XC    2020-04-05    6.8
Fleet1695475-XC2020-04-1610.2
Fleet1324567-KQ2020-04-257.4
Fleet1324567-KQ2020-04-1215.5
Fleet1893765-JD2020-04-198.9
Fleet1893765-JD2020-04-285.2

 

FILTERS: Year: 2020 | Month: April
RESULT

 

Fleet  Total Unique Positions -
Over (10) Qty
Total Unique Positions - 
Between (7-10) Qty
Total Unique Positions - 
Below (7) Qty
Fleet1    111

 

I'll be very grateful if anyone can help me!

Regards,
Alexandre Martins

1 ACCEPTED SOLUTION
alexandrem79
Frequent Visitor

I was able to prepare a solution after watching the video on the link below:
Calculate The Last Or Max Value Within A Table Of Data Using DAX In Power BI

Solution:

Measure Max Date Position =
VAR CurrentPosition = SELECTEDVALUE(inspections[Position])

RETURN
MAXX(
FILTER( ALLSELECTED(inspections), inspections[Position] = CurrentPosition),
inspections[Date] )
)

Measure Over 10 =
CALCULATE(
DISTINCTCOUNT(inspections[Position]),
inspections[Value] > 10,
FILTER(inspections, inspections[Date] = [Max Date Position])
)

Measure Between 7-10 =
CALCULATE(
DISTINCTCOUNT(inspections[Position]),
inspections[Value] >= 7,
inspections[Value] <= 10,
FILTER(inspections, inspections[Date] = [Max Date Position])
)

Measure Below 7 =
CALCULATE(
DISTINCTCOUNT(inspections[Position]),
inspections[Value] < 7,
FILTER(inspections, inspections[Date] = [Max Date Position])
)


Thank you all,
Regards!

View solution in original post

6 REPLIES 6
alexandrem79
Frequent Visitor

I was able to prepare a solution after watching the video on the link below:
Calculate The Last Or Max Value Within A Table Of Data Using DAX In Power BI

Solution:

Measure Max Date Position =
VAR CurrentPosition = SELECTEDVALUE(inspections[Position])

RETURN
MAXX(
FILTER( ALLSELECTED(inspections), inspections[Position] = CurrentPosition),
inspections[Date] )
)

Measure Over 10 =
CALCULATE(
DISTINCTCOUNT(inspections[Position]),
inspections[Value] > 10,
FILTER(inspections, inspections[Date] = [Max Date Position])
)

Measure Between 7-10 =
CALCULATE(
DISTINCTCOUNT(inspections[Position]),
inspections[Value] >= 7,
inspections[Value] <= 10,
FILTER(inspections, inspections[Date] = [Max Date Position])
)

Measure Below 7 =
CALCULATE(
DISTINCTCOUNT(inspections[Position]),
inspections[Value] < 7,
FILTER(inspections, inspections[Date] = [Max Date Position])
)


Thank you all,
Regards!

v-yingjl
Community Support
Community Support

Hi @alexandrem79 ,

I have created a calculated table to achieve this:

Table = 
SUMMARIZE (
    'inspections',
    'inspections'[Fleet],
    'inspections'[Position],
    "last date", MAX ( 'inspections'[Date] ),
    "Value",
    VAR position = [Position]
    RETURN
        CALCULATE (
            SUM ( inspections[Value] ),
            FILTER (
                ALL ( inspections ),
                inspections[Position] = position
                    && inspections[Date]
                        = CALCULATE (
                            MAX ( inspections[Date] ),
                            FILTER ( ALL ( inspections ), inspections[Position] = position )
                        )
            )
        )
)

Three measures to calculate conditional totals:

Total Unique Positions -Over (10) Qty = 
CALCULATE ( DISTINCTCOUNT ( 'Table'[Value] ), 'Table'[Value] > 10 )
Total Unique Positions - Between (7-10) Qty = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Value] ),
    'Table'[Value] >= 7
        && 'Table'[Value] <= 10
)
Total Unique Positions - Below (7) Qty = 
CALCULATE ( DISTINCTCOUNT ( 'Table'[Value] ), 'Table'[Value] < 7 )

result.png

 

Sample file is attached that hopes to help you, please check and try it: Calculate the distinct positions considering the last inspection in the month the vehicle.pbix 

 

Best Regards,
Yingjie Li

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

Ashish_Mathur
Super User
Super User

Hi,

How have you got those answers - 1 for each?  Shouldn't the answer of Total Unique Positions - Over (10) Qty be 2?


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

Thanks for your answer!

I need the value of the most recent inspection of the month:

 

FleetPositionDateValue
Fleet1 695475-XC2020-04-056.8
Fleet1    695475-XC2020-04-1610.2

 

FleetTotal Unique Positions -
Over (10) Qty
Total Unique Positions - 
Between (7-10) Qty
Total Unique Positions - 
Below (7) Qty
Fleet1    100

 

I tried that, but it did not work:

Total Unique Positions - Over (10) Qty =

CALCULATE(
DISTINCTCOUNT(inspections[Position]),
FILTER(inspections, inspections[Value] > 10),
FILTER(inspections, inspections[Date] = MAX(inspections[Date]))
)
 
It's calculating the last date of the table and ignoring the position of the vehicle.

@alexandrem79 , Please find the attached solution file. You may have to change no of groupbys in summarize as per need.

 

The measure is the latest. and measure 2 is the latest in month

 

 

 

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

Hi,

The most recent inspection for the month is 16 April 2020 for 695475-XC and 12 April 2020 for 324567-KQ.  The value for both such instances is > 10 so thae answer should be 2.  You may download my PBI file from here.

Hope this helps.


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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.