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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
FranMullor
New Member

Using Datediff + If with dates in a Measure, not in calculated colum

Hi All!!!

 

I want to use something like this in a measure, not in calculated calumm because of the context, i want to get de vale only in de max of dFecha (date)

 

DiasPendientes =
CALCULATE(IF(MAX(FactProveedores[FechaCobro])>max(dFechas[Fecha]);DATEDIFF(MAX(FactProveedores[Fecha]);MAX(dFechas[Fecha]);DAY);BLANK());FactProveedores[IdOrigen]=-3)
 
de problem here is that the "MAX" doesnt work, so I need to get something like that whitout using the MAX i all the FactProveedores (Supliers)
 
Thanks in advance for the help!
 
🙄
 
 
1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@FranMullor ,

 

You may modify the measure like pattern below:

DiasPendientes =
CALCULATE (
    IF (
        CALCULATE ( MAX ( FactProveedores[FechaCobro] ); ALL ( FactProveedores ) )
            > CALCULATE ( MAX ( dFechas[Fecha] ); ALL ( dFechas ) );
        DATEDIFF (
            CALCULATE ( MAX ( FactProveedores[Fecha] ); ALL ( FactProveedores ) );
            CALCULATE ( MAX ( dFechas[Fecha] ); ALL ( dFechas ) );
            DAY
        );
        BLANK ()
    );
    FactProveedores[IdOrigen] = -3
)

 

Community Support Team _ Jimmy Tao

If this post helps, then 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-yuta-msft
Community Support
Community Support

@FranMullor ,

 

You may modify the measure like pattern below:

DiasPendientes =
CALCULATE (
    IF (
        CALCULATE ( MAX ( FactProveedores[FechaCobro] ); ALL ( FactProveedores ) )
            > CALCULATE ( MAX ( dFechas[Fecha] ); ALL ( dFechas ) );
        DATEDIFF (
            CALCULATE ( MAX ( FactProveedores[Fecha] ); ALL ( FactProveedores ) );
            CALCULATE ( MAX ( dFechas[Fecha] ); ALL ( dFechas ) );
            DAY
        );
        BLANK ()
    );
    FactProveedores[IdOrigen] = -3
)

 

Community Support Team _ Jimmy Tao

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

az38
Community Champion
Community Champion

Hi @FranMullor 

it's absolutely unclear what do you want. if try to decomposite it could look like

DiasPendientes =
var _maxFechaCobro = CALCULATE(MAX(FactProveedores[FechaCobro]);FactProveedores[IdOrigen]=-3)
var _maxFecha = CALCULATE(max(dFechas[Fecha]))
RETURN
IF(_maxFechaCobro > _maxFecha; _maxFechaCobro - _maxFecha; BLANK())

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
amitchandak
Super User
Super User

@FranMullor 

You need to force a row context in measure

Refer my blog on that : https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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