Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi,
I´m trying to create a DAX that would show my total sales in future. So if I select May 18 I would like to see sales total from June 18-Dec 18. Same with half year.
Haven´t found any good tips from community by far. Does anyone has a good tip how to do this?
Thanks in advance!
Solved! Go to Solution.
Hi,
Here's a start
=CALCULATE(SUM(Data[Sales]),DATESBETWEEN(Calendar[Date],MAX(Calendar[Date])+1,DATE(YEAR(MAX(Calendar[Date])),12,31)))
There should be a Calendar Table and an active relatiosnhip from the Date column of your source data Table to the Date column of your Calendar Table. In the Calendar Table, write these calculated column formuals to extract the Month and Year
=YEAR(Calendar[Date])
=FORMAT(Calendar[Date],"mmmm")
In the Filter/slicer, select a certain Year and Month which you dragged from the Calendar Table.
Hi,
Here's a start
=CALCULATE(SUM(Data[Sales]),DATESBETWEEN(Calendar[Date],MAX(Calendar[Date])+1,DATE(YEAR(MAX(Calendar[Date])),12,31)))
There should be a Calendar Table and an active relatiosnhip from the Date column of your source data Table to the Date column of your Calendar Table. In the Calendar Table, write these calculated column formuals to extract the Month and Year
=YEAR(Calendar[Date])
=FORMAT(Calendar[Date],"mmmm")
In the Filter/slicer, select a certain Year and Month which you dragged from the Calendar Table.
Hi @Ashish_Mathur ,
How do you modify the formula if you need to add an additional filter based on a selected value?
Below is my formula. I need to make the 'Data'[Forecast Version] be based on a selectedvalue but don't know how to do this.
-This gives me an error saying I'm using SELECTEDVALUE in a True/False expression
-This doesn't give me an error but returns blank values
-This one works, but I have a number hard coded in, which I don't want as the user needs to determine the version
I finally figured it out. I needed to make make the selection a variable and then return it. This was about 4 hours spent trying to figure this out. I really hate Power BI about half the time.
The Answer
VAR _version = SELECTEDVALUE([Version])
RETURN
Hi @Kmur,
Based on my assumption, I created below sample table ('Test1') to test.
Create a calendar table which is unrelated to 'Test1'. And add a calculated column to get the corresponding date 6 months later. I formatted [Date] to "MMMM yyyy" under Modeling tab. Place [Date] field into slicer.
Dim date = VAR tempTb = CALENDAR ( DATE ( 2018, 1, 1 ), DATE ( 2019, 12, 31 ) ) RETURN ADDCOLUMNS ( FILTER ( tempTb, [Date] >= MAXX ( FILTER ( tempTb, YEAR ( [Date] ) = YEAR ( EARLIER ( [Date] ) ) && MONTH ( [Date] ) = MONTH ( EARLIER ( [Date] ) ) ), [Date] ) ), "Month", MONTH ( [Date] ) )
6 month later =
DATEADD ( 'Dim date'[Date].[Date], 7, MONTH )
Create measures:
start date = SELECTEDVALUE('Dim date'[Date]) +1 End date = SELECTEDVALUE('Dim date'[6 month later]) Total sales = CALCULATE(SUM(Test1[Sales]),DATESBETWEEN(Test1[Date],[start date],[End date]))
Best regards,
Yuliana Gu
Hi Yuliana,
Thank you for you quick reply. Your solution will work as one time calculation but in my case I need the formula working with all months in one year. So that I´d be able to browse through months. Basically logic should be the same as for YTD just to the future.
Br, Kertu
Hi,
I am not sure of whom you are replying to. Have you tried my solution?
User | Count |
---|---|
141 | |
113 | |
104 | |
78 | |
64 |
User | Count |
---|---|
136 | |
125 | |
107 | |
70 | |
61 |