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
PwrBI01
Post Patron
Post Patron

Cumulative value with Userelationship

Hi guys,

 

I have the following table (it contains the measure 'Pendiente de cobro'):

 

 Imagen4.png

 

And I would like to obtain the following one:

 

Imagen5.png

 

The main problem is that the table calendar 'T_Calendar' and the data table 'T_FacturacionExpedienteResumida' are not directly relationated, so I used the function Userelationship, as you can see:

 

Imagen3.png

 

The measure is the following one:

 

Pendiente de cobro = 
Var Facturado = CALCULATE(SUM(T_FACTURACIONEXPEDIENTERESUMIDA[TOTALAPAGAR]);T_FACTURACIONEXPEDIENTERESUMIDA[DIASSINCOBRAR]>0;USERELATIONSHIP(T_CALENDARIO[Fecha];T_FACTURACIONEXPEDIENTERESUMIDA[FECHAFACTURA]))
Var Cobrado = CALCULATE(SUM(T_FACTURACIONEXPEDIENTERESUMIDA[ENTRADA]);T_FACTURACIONEXPEDIENTERESUMIDA[DIASSINCOBRAR]>0;USERELATIONSHIP(T_CALENDARIO[Fecha];T_FACTURACIONEXPEDIENTERESUMIDA[FECHAFACTURA]))
Var PendienteCobro = Facturado-Cobrado
Return
PendienteCobro

 

How can I change it to get the cumulative values?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Hi guys,

 

I have solved the problem.

 

The measure I need to introduce is:

 

Pendiente de cobro =
Var Facturado = CALCULATE(SUM('T_FACTURACIONEXPEDIENTERESUMIDA'[TOTALAPAGAR]);'T_FACTURACIONEXPEDIENTERESUMIDA'[DIASSINCOBRAR]>0;USERELATIONSHIP(T_CALENDARIO[Fecha];'T_FACTURACIONEXPEDIENTERESUMIDA'[FECHAFACTURA]);FILTER(ALL(T_CALENDARIO[Fecha]);T_CALENDARIO[Fecha]<=MAX(T_CALENDARIO[Fecha])))
Var Cobrado = CALCULATE(SUM('T_FACTURACIONEXPEDIENTERESUMIDA'[ENTRADA]);'T_FACTURACIONEXPEDIENTERESUMIDA'[DIASSINCOBRAR]>0;USERELATIONSHIP(T_CALENDARIO[Fecha];'T_FACTURACIONEXPEDIENTERESUMIDA'[FECHAFACTURA]);FILTER(ALL(T_CALENDARIO[Fecha]);T_CALENDARIO[Fecha]<=MAX(T_CALENDARIO[Fecha])))
Var PendienteCobro = Facturado-Cobrado
Return
PendienteCobro

View solution in original post

7 REPLIES 7
PwrBI01
Post Patron
Post Patron

Hi @VijayP 

 

Thank you for your answer but it does not work as I expected.

 

I made some changes:

1. Put the relationship as inactive because I need to have it like this.

2. Create a new measure called 'Test 4' which gives the following results:

Imagen 5.png

 

The result for 2019 is working correctly, but it is not the case for 2017 and 2018, because the results should be the following ones:

Imagen5.png

 

I think the problem is that the measure is not applying correctly the maximum date for each year (the part I put in bold):

 

Test 4 =
Var Facturacion = CALCULATE(SUM('T_FACTURACIONEXPEDIENTERESUMIDA'[TOTALAPAGAR]);'T_FACTURACIONEXPEDIENTERESUMIDA'[DIASSINCOBRAR]>0)
Var Cobro = CALCULATE(SUM('T_FACTURACIONEXPEDIENTERESUMIDA'[ENTRADA]);'T_FACTURACIONEXPEDIENTERESUMIDA'[DIASSINCOBRAR]>0)
Var PendienteCobro = Facturacion-Cobro
Var PendienteCobroAcumulado = CALCULATE(PendienteCobro;USERELATIONSHIP(T_FACTURACIONEXPEDIENTERESUMIDA[FECHAFACTURA];T_CALENDARIO[Fecha]);FILTER(ALLSELECTED(T_CALENDARIO[Fecha]);T_CALENDARIO[Fecha]<=MAX(T_CALENDARIO[Fecha])))
Return
PendienteCobroAcumulado

 

The link to the file is https://www.dropbox.com/s/kip4r60nztzkzmc/Prueba%20Power%20BI.pbix?dl=0

 

Thanks in advance

 

Regards

Hi guys,

 

I have solved the problem.

 

The measure I need to introduce is:

 

Pendiente de cobro =
Var Facturado = CALCULATE(SUM('T_FACTURACIONEXPEDIENTERESUMIDA'[TOTALAPAGAR]);'T_FACTURACIONEXPEDIENTERESUMIDA'[DIASSINCOBRAR]>0;USERELATIONSHIP(T_CALENDARIO[Fecha];'T_FACTURACIONEXPEDIENTERESUMIDA'[FECHAFACTURA]);FILTER(ALL(T_CALENDARIO[Fecha]);T_CALENDARIO[Fecha]<=MAX(T_CALENDARIO[Fecha])))
Var Cobrado = CALCULATE(SUM('T_FACTURACIONEXPEDIENTERESUMIDA'[ENTRADA]);'T_FACTURACIONEXPEDIENTERESUMIDA'[DIASSINCOBRAR]>0;USERELATIONSHIP(T_CALENDARIO[Fecha];'T_FACTURACIONEXPEDIENTERESUMIDA'[FECHAFACTURA]);FILTER(ALL(T_CALENDARIO[Fecha]);T_CALENDARIO[Fecha]<=MAX(T_CALENDARIO[Fecha])))
Var PendienteCobro = Facturado-Cobrado
Return
PendienteCobro
VijayP
Super User
Super User

@PwrBI01 

Look at the Formula for TEST 3 to get your solution

PBIX Attached

VijayP_0-1612455879060.png

 




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


VijayP
Super User
Super User

@PwrBI01 

Sample Data would help to give more clear solution. Appreciate Your Kudos!




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


Hi @VijayP

 

I send you a sample data (this is not the original one, which is much bigger), so I need to keep the not activated relationship between both tables.

 

The link is https://www.dropbox.com/s/kip4r60nztzkzmc/Prueba%20Power%20BI.pbix?dl=0

 

Thanks in advance.

VijayP
Super User
Super User

@PwrBI01 

This is the formula to create Virtual Relationship
Revenue based on delivery date = CALCULATE([Total Revenue],USERELATIONSHIP(Dates[Date],Sales[Delivery Date]))
 Cumulative Delivery =
CALCULATE([revenue based on delivery date],FILTER(ALL(Dates),Dates[Date]<=MAX(Dates[Date])))
 Hope this helps!
 



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


Hi @VijayP,

 

Thank you for your answer, I tried it but it doesn't work.

 

Regards.

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.