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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.