Format a date in a Power BI Measure - powerbi

I am using conditional formatting with a measure to display a header based on the selection of a slicer. This is the code that is auto generated with the measure along with some text I have added.
Select Year = "Displaying sales for quarter beginning "&SELECTEDVALUE('public all_sales'[sale_date], " Multiple selected quarters")
It results in this as a heading:
"Displaying sales for quarter beginning 1/1/2018"
I just want it to say:
"Displaying sales for quarter beginning JAN 2018"
I have tried adding a format mask, like this:
Select Year = "Displaying sales for quarter beginning "&SELECTEDVALUE(('public all_sales'[sale_date], MM-YYYY) " Multiple selected quarters")
However it does not compile as a correct format and basically I am clutching at straws.
Anyone with decent Power BI had a similar issue or know how to format dates within a Power BI "measure"?

this one should work.
Select Year = "Displaying sales for quarter beginning "&SELECTEDVALUE('public all_sales'[sale_date], " Multiple selected quarters",Format('public all_sales'[sale_date], "MMM YY"))

Try this
Select Year =
VAR result = SELECTEDVALUE('public all_sales'[sale_date])
RETURN
IF(
ISBLANK(result)
,"Displaying sales for quarter beginning "
& "Multiple selected quarters"
)
,"Displaying sales for quarter beginning "
& FORMAT(result,"mmm yyyy")
)
)

Related

what kind of measure or column will use here

[Please refer to the below image. I want to create a stacked column chart but I don't have a column that includes 0-30, 30-60, 60-90, etc. How did I put this range on X-axis?
And I didn't understand what kind of measure is used for "LAST 3 MONTH average" & "LAST 12 MONTH average ".
Can you please assist me with the same? ]
https://i.stack.imgur.com/AEnoa.png
Here is Microsoft documentation on using grouping and binning features in Power BI: https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-grouping-and-binning
You can create a measure for last 3 month average like this:
3 Month Average = CALCULATE(
AVERAGE(Table[value]),
FILTER(Table,
Table[date] >= DATE(YEAR(TODAY()),MONTH(TODAY()-3),DAY(TODAY()))
)
)

How to Get Custom Week Desc in DAX

Basis on below data I want to add a calculated column with Week Description
I've done it in excel by typing it manually.
Also my week is starting from Thursday and ends on Wednesday hence I've Used this function to get the weekday WEEKDAY('Calendar'[date],14)
Requesting you to help me with a dax code which can be used to create a new calculated column with week information as shown below in third column.
The logic would be : If the date is current week then the value will be "This Week" else if the
date is in last week then "This Week -1" else if the date is in last to last week then "This Week - 2" and so on.
The weekday can be calculated as following:
Weekday = WEEKDAY([Date] + 3)
We do a shift of 3 days to make Thursday the start of the week
Next, we get the WeekDesc in two steps, frist we calculate the difference between now and the date in weeks and as second step we use an if statement to create the correct sting (and logic).
WeerDesc =
var weeksPast = DATEDIFF(now(), [Date] + 3,WEEK)
return if ( weeksPast = 0, "This Week", "This Week" & weeksPast)
As you can see you can use variables in your DAX, I would recommend using them to keep the overview.
Enjoy
We can do this also in this way (as a measure if you need only label to display on rows):
DayOfWeek = WEEKDAY(SELECTEDVALUE('CAL'[Date]),14)
DiffToToday = DATEDIFF(SELECTEDVALUE('CAL'[Date]),TODAY(),DAY)
Label = CONCATENATE("This Week", (DIVIDE( CAL[DiffToToday] + CAL[DayOfWeek],7) -1) *-1 )
Of course, we can do all steps in one measure.

Last Year vs Current Selected Year

I have been creating a dashboard in which I am trying to showing current Selected year vs last year analysis. Please see the below image :
As you see in the above image, 2020 year selected from the slicer and 2020 sales is 4.30M.
Expectation : I want to show the last year difference with Arrow sign means if the current year sales is greater than last year than "Green upper arrow" and if the last year sales greater than current year then "Red down arrow".
Thing I Tried : I have created a DAX, but it not showing any value to me :
Previous Year Sales = CALCULATE(sum(Orders[Sales]),PREVIOUSYEAR(Orders[Order Date]))
Option 2 : I have also tried this one (it show me value but desired results):
same period last year = CALCULATE(Sum(Orders[Sales]),SAMEPERIODLASTYEAR(Orders[Order Date]))
Expected Output ( Current Year vs last year percentage with Arrow sign) :
Sample data link :
http://www.cse.ohio-state.edu/~hwshen/Melbourne/Data/Superstore.xlsx
How can I achieve the above ?
Thanks
The percentage should be straight foward. Keep in mind you need a DATE TABLE or use the automatic datetime created by power bi, for that you need to reference it with ".[Date]"
same period last year = CALCULATE(Sum(Orders[Sales]),SAMEPERIODLASTYEAR(Orders[Order Date].[Date]))
Sales YoY % =
VAR _ly = [same period last year]
RETURN
DIVIDE(_ly-Sum(Orders[Sales]),_ly)
Format you [Sales YoY %] measure as a percentage.
The visual part you can do it multiple ways, cards, HTML, KPIs Visuals or Table/Matrix conditional formating.

PowerBI Measure - Previous Quarter With Filter

I am trying to create a measure to calculate the sum of sales for the previous quarter with a filter.
This is what I tried:
PQ Retail Sales = CALCULATE(SUM(MASTER_SALES_REPORTING_COMPETITION[Retail Sales $]),
FILTER(MASTER_SALES_REPORTING_COMPETITION,
MASTER_SALES_REPORTING_COMPETITION[Vendor Grouped] = "Company A"),
PREVIOUSQUARTER(DateDim[Date]))
Is there a logical error with the dax? PowerBI doesn't pick up any errors however I get a blank result.
Thank you.

DAX running sum in custom periods Year to year

I have a table with the name of certain promotional periods and their start and end dates for the current year (every year it will be a new table with slightly different periods). I need to calculate running sum of sales between the start and end date of selected period and compare it to the same period last year and show it on a chart for comparison.
Ok, so I've found a workaround, but it's working:
First I take just day and month from start and end dates for each period:
Start = FORMAT(VALUES('Promo'[start]); "dd-MM")
End = FORMAT(VALUES('Promo'[end]); "dd-MM")
then for the current year and for previous year I create measures used for filtering the sales:
Sales start = DATEVALUE([Start] & "-" & [Year])
Sales start LY = DATEVALUE([Start] & "-" & [Y-1])
Sales end = DATEVALUE([End] & "-" & [Year])
Sales end LY = DATEVALUE([End] & "-" & [Y-1])
and I use those dates in the running total calculation for this year and Y-1.
Now when I make a slicer with Promotional period names and select one of the periods all is being calculated correctly.
The thing I still need to solve is how to put those running totals on one chart for comparison.