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
Anonymous
Not applicable

Need to dynamically calculate status

Hello, I'm in need of a helping hand with the following measure.

I need to calculate the status of an invoice according to two things - the last date selected by the user on the slicer and the day of payment for the invoice that is in my database. As such, if there is no date of payment for the invoice, or the date of payment is higher than the last date selected by the user, it has a status of 'Pendente', otherwise, it has the 'Compensado' status. I have a working version of it, displayed below, but it's too costly in terms of resources and cannot be displayed for the client in PowerBI. What can I do to optimize it?

StatusPagamentoCalculado:=
var Data = LASTDATE(Calendario[Date])
var pend = IF (SELECTEDVALUE(FatoContasAReceber[DataCompensacao]) = BLANK();
	         "PENDENTE";
	         IF(SELECTEDVALUE(FatoContasAReceber[DataCompensacao]) <= Data;"COMPENSADO";"PENDENTE"))
RETURN pend
4 REPLIES 4
Stachu
Community Champion
Community Champion

does this measure return the expected results?

StatusPagamentoCalculado = 
VAR __DateSlicer =
    MAX ( Calendario[Date] )
VAR __DateInvoice =
    MAX ( FatoContasAReceber[DataCompensacao] )
VAR __Status =
    IF (
        __DateInvoice = BLANK (),
        "PENDENTE",
        IF ( __DateInvoice <= __DateSlicer, "COMPENSADO", "PENDENTE" )
    )
RETURN
    __Status

it should have better performance than the original one - the invoice date is evaluated once, and MAX should be faster than SELECTEDVALUE



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Thanks for the reply.

It does works better, but it doesn't display correctly - I need the measure to be different for every invoice, and I can't use a calculated column due to the need for it to be dynamic. Even if otherwise, the measure still breaks when I have a larger amount of invoices to show. 

Anonymous
Not applicable

Sorry for the double post, but I think I have discovered the problem - for each invoice, it calculates the measure for all rows of the Calendar table, which makes it have about 14 billion rows, breaking the memory limit.

Stachu
Community Champion
Community Champion

I assume you don't display the measure for all dates/invoices, is that correct? Why do you think it iterates over the whole calendar table, do you use it later that way?

you could still add it as a temporary calculated column if it's needed for the calculations later, but in order to write tat I would need to understand what you're trying to achieve



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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