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
Hello,
I am trying to add new column to compare the data with the previous data based on the filter
the filter contains (QTD-YTD-MTD-Yesterday) options
how I can make the prev - net sales column contain the previous period ?
Hi all,thanks for the quick reply, I'll add more.
Hi @manar_alamri ,
Try this
Measure =
VAR _timeFrame = SELECTEDVALUE('yourtable'[Time Frame])
RETURN
SWITCH(TRUE(),
_timeFrame = "Yesterday",CALCULATE([Net Sales],'FactTable'[Date] = TODAY()-1),
_timeFrame = "MTD",CALCULATE([Net Sales],DATESMTD('FactTable'[Date])),
_timeFrame = "ATD",CALCULATE([Net Sales],DATESQTD('FactTable'[Date])),
_timeFrame = "ytd",CALCULATE([Net Sales],DATESYTD('FactTable'[Date]))
)
Best Regards
Hello @manar_alamri,
You can use the SAMEPERIODLASTYEAR, PARALLELPERIOD, or DATEADD functions to calculate previous period sales based on the selected filter.
Prev_Net_Sales =
VAR _TimeFrame = SELECTEDVALUE('Time Frame'[Time Frame])
RETURN
SWITCH(
TRUE(),
_TimeFrame = "Yesterday", CALCULATE(SUM('Sales'[Net Sales]), DATEADD('Date'[Date], -1, DAY)),
_TimeFrame = "MTD", CALCULATE(SUM('Sales'[Net Sales]), PARALLELPERIOD('Date'[Date], -1, MONTH)),
_TimeFrame = "QTD", CALCULATE(SUM('Sales'[Net Sales]), DATESQTD(PREVIOUSQUARTER('Date'[Date]))),
_TimeFrame = "YTD", CALCULATE(SUM('Sales'[Net Sales]), SAMEPERIODLASTYEAR('Date'[Date])),
BLANK()
)
Thank you @Sahir_Maharaj , it works. However, when selecting the filter based on the quarterly period, the data doesn't appear. Should we have completed at least three months in the current year for it to match with the previous quarter, or is there another reason?
Is the picture what you are trying to achieve, otherwise im not quite sure what you mean. You want a visual with net sales and compare against (QTD, YTD etc).
I would create measures for that, not extra columns.
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 |
|---|---|
| 53 | |
| 40 | |
| 38 | |
| 19 | |
| 18 |
| User | Count |
|---|---|
| 70 | |
| 69 | |
| 34 | |
| 33 | |
| 30 |