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
phyconia
Frequent Visitor

Get average from -90 day from the start date to end date based on slider.

Hello I am pretty new to powerbi and i dont know what this code is doing but it doesnt seem to break anything. Is this looking for the average volume of cars between -90 days from the first selected date to last selected date ?

Car Inital =
IF(
    ISFILTERED('Calendar'[Date]),
    VAR __Firstdate = FIRSTDATE('Calendar'[Date])
VAR __Lastdate = LASTDATE('Calendar'[Date])
    RETURN
        AVERAGEX(DATESBETWEEN('Calendar'[Date],DATEADD(__Firstdate, -90, DAY),__Lastdate),
            CALCULATE(AVERAGEX(KEEPFILTERS(VALUES('Calendar'[Date])),CALCULATE(SUM('master_csv'[Car]))))
        )
)
1 ACCEPTED SOLUTION

@phyconia , Are you looking for something like this

 

Car Inital =
IF(
ISFILTERED('Calendar'[Date]),
VAR __Firstdate = FIRSTDATE('Calendar'[Date])
VAR __Lastdate = LASTDATE('Calendar'[Date])
RETURN
CALCULATE(AVERAGEX(VALUES('Calendar'[Date]),CALCULATE(SUM('master_csv'[Car]))) ,
DATESBETWEEN('Calendar'[Date],DATEADD(__Firstdate, -90, DAY),__Lastdate) )

View solution in original post

4 REPLIES 4
SpartaBI
Community Champion
Community Champion

@phyconia check out this article: https://www.daxpatterns.com/standard-time-related-calculations/
Read it carefully and it will give you what you need and much more


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Thank you I have already been through this article to no avail. thank you for your responce  🙂 

@phyconia , Are you looking for something like this

 

Car Inital =
IF(
ISFILTERED('Calendar'[Date]),
VAR __Firstdate = FIRSTDATE('Calendar'[Date])
VAR __Lastdate = LASTDATE('Calendar'[Date])
RETURN
CALCULATE(AVERAGEX(VALUES('Calendar'[Date]),CALCULATE(SUM('master_csv'[Car]))) ,
DATESBETWEEN('Calendar'[Date],DATEADD(__Firstdate, -90, DAY),__Lastdate) )

@phyconia ok, I'm not sure what you are trying to do. Can you share the file and hard code in a text box the result you want to get and the logic behind it.
P.S. will appreciate your 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.