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
dpc_development
Helper III
Helper III

Calculating average of a column's current row divided by the first

Please see the file I have shared in the following link:

https://drive.google.com/file/d/1q7FE85qHoB_OhAm4hlmFidh6WP3m-UnK/view?usp=sharing

 

I have a dataset with the value of various items on different dates. I first need to calculate ratio by dividing the value of an item on a particular date with the earliest value in the chosen date filters. I then need to show the per day ratio of all items (columns I & J) as the desired output.

 

I am able to get the "first value" in the filtered table by using the following formula:

first_cr = 
VAR item = MAX('Table 1'[item])
VAR min_updated = CALCULATE(
    MIN('Table 1'[last_updated]),
    'Table 1'[item] = item,
    ALLSELECTED('Table 1')
)
RETURN
CALCULATE(
    AVERAGE('Table 1'[cr]),
    'Table 1'[last_updated] = min_updated,
    'Table 1'[item] = item,
    ALLSELECTED('Table 1'[fk])
)

 

However, I am unable to figure out how to calculate the average of all the individual item ratios at just the date level. I guess I need to use AVERAGEX somehow, but not sure how. Perhaps my first_cr formula could use more refinement.

 

I'd appreciate any help or guidance in the right direction. Thanks for your time.

1 ACCEPTED SOLUTION
dpc_development
Helper III
Helper III

I was able to write a working formula for my requirement. If anyone can refine it better, I'd appreciate that...

 

ret = 
var lastUpdated = MAX(Sheet1[Date])
var tbl = ALLSELECTED(Sheet1)
RETURN 
CALCULATE(
    AVERAGEX(
        Sheet1,
        var i = Sheet1[Item]
        var minUpdated = CALCULATE(
            MIN(Sheet1[Date]),
            Sheet1[Item] = i,
            tbl
        )
        var first_cr = CALCULATE(
            AVERAGE(Sheet1[Return]),
            Sheet1[Date] = minUpdated,
            Sheet1[Item] = i,
            tbl
        )

        RETURN Sheet1[Return] / first_cr
    ),
    Sheet1[Date] = lastUpdated,
    tbl
)

View solution in original post

2 REPLIES 2
dpc_development
Helper III
Helper III

I was able to write a working formula for my requirement. If anyone can refine it better, I'd appreciate that...

 

ret = 
var lastUpdated = MAX(Sheet1[Date])
var tbl = ALLSELECTED(Sheet1)
RETURN 
CALCULATE(
    AVERAGEX(
        Sheet1,
        var i = Sheet1[Item]
        var minUpdated = CALCULATE(
            MIN(Sheet1[Date]),
            Sheet1[Item] = i,
            tbl
        )
        var first_cr = CALCULATE(
            AVERAGE(Sheet1[Return]),
            Sheet1[Date] = minUpdated,
            Sheet1[Item] = i,
            tbl
        )

        RETURN Sheet1[Return] / first_cr
    ),
    Sheet1[Date] = lastUpdated,
    tbl
)

Hi @dpc_development ,

Glad to hear that. Please accept your reply above as a solution so that people who may have the same question can get the solution directly.

 

Best Regards,
Icey

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.