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.
HI PBI Experts ,
Here is my question for you in dax ,
i want to know the sales of the "current month", "last month", "last before month sales" by using the Dax.
i am using previousmonth dax function and i want to know for current month , before previous month dax function.
will give kudos
Advance Thanks,
Thanks
sandeep
Solved! Go to Solution.
Hi @avulasandeep,
If you only want to calculate the sales of "current month", "last month", "last before month sales" by using the Dax, you could try the formula below.
current_month_sales = CALCULATE(SUM('Table1'[Sales]),FILTER('Table1',MONTH('Table1'[Month])=MONTH(TODAY()))) last_month_sales = var current_month= MONTH(TODAY()) return CALCULATE(SUM('Table1'[Sales]),FILTER('Table1',MONTH('Table1'[Month])=current_month -1)) last before_month_sales = var current_month= MONTH(TODAY()) return CALCULATE(SUM('Table1'[Sales]),FILTER('Table1',MONTH('Table1'[Month])=current_month -2))
Here is the output.
Best Regards,
Cherry
Hello, I just wonder, why do you use the 'FILTER' function within 'CALCULATE' - does it have any purpose?
I'm asking because for me the formula works without it:
Volume 2 Months Before:=CALCULATE(COUNTROWS(Table),MONTH(Table[Date])=MONTH(TODAY())-2)
@Anonymous there are some filter scenarioes where FILTER is 100% required. From discussions i've had with other datanauts, there is an argument to be made to use the FILTER inside the calculate for optimisation as the filter is used behind the scenes regardless.
I still personally avoid filter unless absolutely necessary as it feel it makes for shorter cleaner code, however I am concious when i'm optmising my model, that that is a place for me to review.
@Anonymous thanks for such a quick response! I'm also a fan of having the code leaner, but I'm now curious of the cases where you need FILTER - could you send me link to such discussion you mentioned?
Off the top of my head, 2 examples would be if you have complex AND and OR statements. Also if you do a calculatetable and place it into a variable.
Hi Power BI community,
Just a question regarding a small alteration to the question hear.
What should be typed in DAX if instead of basing the data around "current month" we want to use the month selected on a slicer as the benchmark?
Thanks,
Gdexter
Rather than using DAX for this solution, i'd suggest instead creating a Date Table and store a True/False value against the dates that conform to the periods you care about. You would end up with 3 different flags. Then you can create 3 visuals based on the "Sum" of sales, and apply those flags to constrain the dates to the 3 different date ranges.
In Power Query you can get todays date by using:
Date.From(DateTime.LocalNow())
You can extract years, months and days from this. An example of a previous month True/False would be:
if [Year] = Date.Year(DateTime.LocalNow()) then if Date.Month(DateTime.LocalNow()) = 1 then [Month Number] = 12 else [Month Number] = (Date.Year(DateTime.LocalNow()) - 1) else "FALSE"
In the code above, this is a column added to my date table that has a YEAR and MONTH column.
i need all the below selected months in dax .
That means
Current month sales using dax :
previous month sales using dax :
before previous month sales using dax :
Thanks
sandeep
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
98 | |
86 | |
70 | |
62 |
User | Count |
---|---|
151 | |
120 | |
103 | |
87 | |
68 |