Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreThe FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now
I need to get total purchase quantity from purchase table for last 12 months but with two conditions.
i. 12 months count will start from last date of purchase
ii. Purchase should not be included from the month/date given in report slicer (current context).
My approach is to get last purchase date first meeting above conditions and then calculate purchase quantity by using DATESINPERIOD function.
To get last purchase date, e.g. in below image, date range is given from 1st Jul to 31st Jul and sku slicer has selected four SKUs.
below is the DAX to get this result.
var max_date = calculate(
maxx(purchases,'purchases'[trnx_date]),
purchases[trnx_type] = "Purchase",
all('calendar'[date])
)
return max_date
According to my two conditions, dates in July and August should not reflect here, rater these purchas date should be might be in june or any other month.
Can anyone help, how to achieve this?
Solved! Go to Solution.
Sorry, my mistake. Please try this one
var min_day_slicer = if (ISFILTERED('calerdar[date]), MIN ('calerdar[date]), MAX ('calerdar[date]))
return MAXX(CALCULATETABLE(purchase,REMOVEFILTER('calerdar[date]),'purchase[trnx_date] < min_day_slicer),'purchase[trnx_date])
I tried below code and it worked.
calculate(
max(purchases[trnx_date]),
datesinperiod('calendar'[date],startofmonth('calendar'[date])-1,-48,MONTH)
)
but letter @Hoangechip910 has given a better solution and I adopted the same. Below is his code.
var min_day_slicer = if (ISFILTERED('calendar'[date]), MIN ('calendar'[date]), MAX ('calendar'[date]))
return MAXX(
CALCULATETABLE
(
purchases,
REMOVEFILTERS('calendar'[date]),
'purchases'[trnx_date] < min_day_slicer
),
'purchases'[trnx_date]
)
Thank you everyone for your time and support. ❤️
I tried below code and it worked.
calculate(
max(purchases[trnx_date]),
datesinperiod('calendar'[date],startofmonth('calendar'[date])-1,-48,MONTH)
)
but letter @Hoangechip910 has given a better solution and I adopted the same. Below is his code.
var min_day_slicer = if (ISFILTERED('calendar'[date]), MIN ('calendar'[date]), MAX ('calendar'[date]))
return MAXX(
CALCULATETABLE
(
purchases,
REMOVEFILTERS('calendar'[date]),
'purchases'[trnx_date] < min_day_slicer
),
'purchases'[trnx_date]
)
Thank you everyone for your time and support. ❤️
Hi,
Share some data and show the expected result. Share data in a format that can be pasted in an MS Excel file.
Sorry, my mistake. Please try this one
var min_day_slicer = if (ISFILTERED('calerdar[date]), MIN ('calerdar[date]), MAX ('calerdar[date]))
return MAXX(CALCULATETABLE(purchase,REMOVEFILTER('calerdar[date]),'purchase[trnx_date] < min_day_slicer),'purchase[trnx_date])
Great. It worked and giving desired result. Thanks
It did not work. Nothing returned now.
Hi
Measure
max_date =
var min_day_slicer = if (ISFILTERED('calerdar[date]), MIN ('calerdar[date]), blank())
return MAXX(FILTER(purchase,'purchase[trnx_date] < min_day_slicer),purchase,'purchase[trnx_date])
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 50 | |
| 44 | |
| 44 | |
| 19 | |
| 19 |
| User | Count |
|---|---|
| 71 | |
| 70 | |
| 34 | |
| 33 | |
| 31 |