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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

TRICKY - Average last 6,5,4 and 3 months

Hi Experts

 

See image of the formula in excel where i am trying to calculate the average over the last 6,5,4 and 3 month. I need to re create the average formula in Power BI Based..

 

The average calculation must ALWAYS starts at the bottom of the green cell as shown in the formula below,,

 

Capture.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Sample PBIX with Data

https://www.dropbox.com/s/bko95z5uckgj9j3/sample%283%29.pbix?dl=0 

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

 

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

mahoneypat
Employee
Employee

Thank you for providing a pbix.  What are the values in columns 0-6?  Are those calculated from the Amount column too?  If so, those you should also be done in a measure.  If not, the data should likely be unpivoted to make your analysis/visualization easier (dynamically switching to a different column in a measure would be a challenge too).

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi Mayoneypat

The values are show in the image below and how month 5 is calculated too...and the amount are to be calculated from the column. I would ideally like a measure... please for each column.

 

Capture.PNG

I was trying to understand more about how you generated columns 0-6.  I suspect you should model your data differently to make your analysis differently (or just calculate everything with measures).  For example, this is a measure to get the last 6 months value for the 0 column.

 

Last 6 Mos for 0 Column =
VAR maxdate =
    MAX ( 'Sample Data'[Date] )
VAR priordate =
    EDATE ( maxdate-5 )
RETURN
    CALCULATE (
        AVERAGE ( 'Sample Data'[0] ),
        FILTER (
            ALL ( 'Sample Data'[Month], 'Sample Data'[Date] ),
            'Sample Data'[Date] >= priordate
                && 'Sample Data'[Date] <= maxdate
        )
    )

 

With your current data model, you will need a separate measure for every combination of column (0-6) and months back.  It would be better to unpivot those columns (0-6) and maybe add a disconnected table with values 0-6 and have a single measure that gets all your desired values.  But I don't fully understand your scenario, of course.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.