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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ecoflux38170
Regular Visitor

Problem with negative index on table

Hello everyone,

I am new to PowerBI.
I have a problem with a measure, here is the source of my measure:

Kilométrage =
IF(
ISFILTERED('Chronologie'[Chronologie]),
ERROR("Les mesures rapides de Time Intelligence peuvent être regroupées ou filtrées seulement par la hiérarchie de dates ou les colonnes de dates principales fournies par Power BI."),
VAR __PREV_YEAR = CALCULATE([Index kilométrique(km)], DATEADD('Chronologie'[Chronologie].[Date], -1, YEAR))
RETURN
('Index Kilométrique'[Index kilométrique(km)] - __PREV_YEAR))
I would like to cancel the calculation if one of the values ​​is negative to calculate the number of kilometers of the vehicles in my fleet.
How to do?
Thank you in advance for your help!

Capture d’écran 2023-03-14 152442.png
Capture d’écran 2023-03-14 152549.png

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@ecoflux38170 Try:

Kilométrage = 
IF(
ISFILTERED('Chronologie'[Chronologie]),
ERROR("Les mesures rapides de Time Intelligence peuvent être regroupées ou filtrées seulement par la hiérarchie de dates ou les colonnes de dates principales fournies par Power BI."),
VAR __PREV_YEAR = CALCULATE([Index kilométrique(km)], DATEADD('Chronologie'[Chronologie].[Date], -1, YEAR))
VAR __Value = ('Index Kilométrique'[Index kilométrique(km)] - __PREV_YEAR))
VAR __Result = IF(__Value < 0, BLANK(), __Value)
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@ecoflux38170 Try:

Kilométrage = 
IF(
ISFILTERED('Chronologie'[Chronologie]),
ERROR("Les mesures rapides de Time Intelligence peuvent être regroupées ou filtrées seulement par la hiérarchie de dates ou les colonnes de dates principales fournies par Power BI."),
VAR __PREV_YEAR = CALCULATE([Index kilométrique(km)], DATEADD('Chronologie'[Chronologie].[Date], -1, YEAR))
VAR __Value = ('Index Kilométrique'[Index kilométrique(km)] - __PREV_YEAR))
VAR __Result = IF(__Value < 0, BLANK(), __Value)
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for your solution ! It Works but now, sums are wrong, but it's the sums that interest me the most. I make another post for this other problem.

ecoflux38170_0-1679641796419.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors