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

Accumulate the price per month, taking into account the last date

Good afternoon, I'm needing help with the following:

bi_in_data_0-1608584791294.png

The measurement of test_price in the table on the left is as follows:

test_price =
CALCULATE(CALCULATE(AVERAGE(new_presence_prices[Precios_double] ),LASTDATE(new_presence_prices[created_at]))
,
FILTER ( ALL ( Dates ), Dates[Date] <= MAX ( Dates[Date]))
)

The data in table new_presence_prices is updated only when the price changes, but is always reflected in a line, which generated me that within the evolution chart I could never have the price for each of the months, which in itself was the same.

At the moment what I achieve with this measure is that when it comes to bringing it to the evolution chart, the "uid" that have more than one price or a single price, always respect me the most current in each of the months

The only problem I have is that when within the same month I have more than one "uid" with a price each, I'm always taking the one from the last date, since I'm passing it LASTDATE.

I would like the month 09/2020, for example, to add 6.99 plus 24.95 and then take the average, but since the price of 24.95 is later than 6.99, it only brings me 24.95

2 ACCEPTED SOLUTIONS

That's @bi_in_data.

I'm sorry I didn't realize you didn't have values in all your lines, my evil.

Using your measure I remade the average to:

Last_Price = 
var Average_Price = CROSSJOIN (
    SUMMARIZE (
        FILTER(all(new_presence_prices[Created_at];new_presence_prices[UID]); new_presence_prices[Created_at]<= MAX(Dates[Date]));
        new_presence_prices[UID]
                   );
    VALUES ( Dates[Year_Month] )
)
return
AVERAGEX(Average_Price;[ test_price])

Resutl below and in the attachment:

MFelix_0-1608656147120.png

Once again apoligize for confusion about the data.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

Don't @bi_in_data,

All X formulas are iterator formulas, which means that the calculation is performed row by row.

In this case what I do with the formula is create a table:

Month - UID - trial price

This creates one row for each month for each UID, then I pick up the average of each row, because in the line chart I only have Month to give contex what happens is that for each month we collect all the lines inside (2 UID in this example) and do the averages of those values:

2020-12 - UID 1 - 6.99

2020-12 - UID 2 - 33.95

Average of previous values:

2020-12 - Both UID - 20.47

This is done for each value of each month.

It also has such calculations for SUMX, COUNTX, COUNTAX, etc.

I hope this helps you understand the process.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Felix,

I see it works well in your case, but because the table you're using has the data every month.

As I was saying, I have it only when the price changes.

prices = price_double

bi_in_data_0-1608651180817.png

that's what the table looks like, it would be the uniphacion of those two images.

That's @bi_in_data.

I'm sorry I didn't realize you didn't have values in all your lines, my evil.

Using your measure I remade the average to:

Last_Price = 
var Average_Price = CROSSJOIN (
    SUMMARIZE (
        FILTER(all(new_presence_prices[Created_at];new_presence_prices[UID]); new_presence_prices[Created_at]<= MAX(Dates[Date]));
        new_presence_prices[UID]
                   );
    VALUES ( Dates[Year_Month] )
)
return
AVERAGEX(Average_Price;[ test_price])

Resutl below and in the attachment:

MFelix_0-1608656147120.png

Once again apoligize for confusion about the data.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Thank you very much, I work excellent, the only thing I do not get to understand well is the averagex, I understand that the first part you do a unification of two tables within a variable, but then within the averagex it is not clear to me how it works.

Thank you!!

Don't @bi_in_data,

All X formulas are iterator formulas, which means that the calculation is performed row by row.

In this case what I do with the formula is create a table:

Month - UID - trial price

This creates one row for each month for each UID, then I pick up the average of each row, because in the line chart I only have Month to give contex what happens is that for each month we collect all the lines inside (2 UID in this example) and do the averages of those values:

2020-12 - UID 1 - 6.99

2020-12 - UID 2 - 33.95

Average of previous values:

2020-12 - Both UID - 20.47

This is done for each value of each month.

It also has such calculations for SUMX, COUNTX, COUNTAX, etc.

I hope this helps you understand the process.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @Anonymous ,

 

To what I can understand you want to have the latest price value for each UID and then pickup the average of all the ones within the same month and make the average.

 

Add the following measure:

Average Value = AVERAGEX(VALUES(new_presence_prices[UID]);[test_price])

 

check result below and in attach PBIX file

 

MFelix_0-1608634751261.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Felix thank you for the answer,

The problem is that I have the price data as follows.

UID 1

bi_in_data_0-1608639951474.png

UID 2

bi_in_data_1-1608640041750.png

With the measure of test_prices I managed to bring the price to each month, but when I analyze two UIDs it happens to me that for example for the month of 9-2020 as the first UID has a created_at of 26/9 and the second UID has only one date, which is 2/06, always brings me the latest, since I am using THE LASTDATE.

I would like it to look as you well explained in the evolution chart, the difference is that the price data I have them in this way that I show you above.

Thank you

Hi @Anonymous ,

 

If I understand correctly you want to have the 6.99 of UID 2 consider for the rest of the months and then use that has the average?

 

I believe that is better for you to use the LASTNONBLANK values to get this calculation, I have made the following measures:

 

Last_Price = CALCULATE( LASTNONBLANK(new_presence_prices[precious_double];0);ALLSELECTED(Dates[Date]))
Average Value = AVERAGEX(VALUES(new_presence_prices[UID]);[Last_Price])

Has you can see the Last_Price gives the exact same result has your measure:

MFelix_0-1608647815040.png

However when using this on the AVERAGEX what I'm calculating is: 

2020-12 (6.99 + 33.95) / 2 = 20.47

and so on

 

MFelix_1-1608649194790.png

 

Is this correct?

 

Check PBIX file attach.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.