Need Trended Chart for MAT calculation in Power BI - powerbi

I need to form a trended chart of last 12 months depending on the slicer selection from the user, for one of the MAT calculation. MAT calculation looks like below, here I am using Calendar2 table to find out MAT sum according to month selection, suppose if I have selected Nov 2022 in month slicer(of Calendar table) then it will give me Dec 2021 to Nov 2022 in Calendar2 table. Connection between Calendar and Calendar2 table is inactive ->
var a=MAX(Calendar[Date])
var preious_dates=DATESINPERIOD(Calendar2[Date],a,-12,MONTH)
var Ours=CALCULATE(SUM(Market_Share_Brands[value]),Market_Share_Brands[manufacturer]="Ours",Market_Share_Brands[channels]="D - Commerce",REMOVEFILTERS('Calendar'),
KEEPFILTERS(preious_dates),USERELATIONSHIP('Calendar'[Date],Calendar2[Date]))
var Others=CALCULATE(SUM(Market_Share_Brands[Value]),Market_Share_Brands[Manufacturer]<>"Ours",Market_Share_Brands[Channels]="D - Commerce",REMOVEFILTERS('Calendar'),
KEEPFILTERS(preious_dates),USERELATIONSHIP('Calendar'[Date],Calendar2[Date]))
return DIVIDE(Ours,(Others+Ours))
So this thing is working fine if I want to show particular month's MAT value, but if I need to show trended chart for last 12 months then it filters out the month that is being selected and not the last 12 months.
What should I do to get last 12 month's MAT numbers in trended chart?

Related

Cumulative Sum in PowerBI Matrix Based on Date

I have a matrix in PowerBI that should be a rolling 12 month view of sales, and I need it to be cumulative. This is what I have so far:
Matrix
The Cumulative Sum row has values of 10 for Oct 2022 and Feb 2023, so I would like it to show 0s until Oct 2022, 10s until Feb 2023, and 20s thereafter.
The values look like this in the dataset:
Dataset
EDIT: The dataset is filtered in the image, there will be multiple rows and values for each month in the unfiltered dataset.

Power BI - Selecting and Filtering Columns based on Slicer Selection

Hello Stack Overflow Community,
In the attached excel sheet image, there are 5 columns (cols B to F) that have arbitrary sales numbers for years 2016-2020. In the report there will be a year slicer of each of these years. I want to calculate the total sales depending on the selection in the year slicer. However, there are 15 columns towards the end which dictate whether a particular company should be included in the total sales calculation. Only if the column corresponding to the selection by the user is N, the value should be included in the total sales calculation.
Example: If the user selects 2016,2017 and 2018 in the year slicer, Power BI should look into the column Excluded 2016-2017-2018 and include/ exclude the sales numbers of the respective years and finally return a table as below
Year Sales (Total)
2016 393
2017 561
2018 580
There is two problem in your case : the first is to be able to calcule with the filter and I think it will be easier if you do this in Excel and the second problem is to use a filter on a combinaison of imput to select only one value.
For the fist problem you could probably do something like that :
=IF(H2="Y";F2;0) / =IF(I2="Y";G2;0) / =IF(J2="Y";G2+F2;0)
and use the power of excel to slide the formula to the bottom of your table
And the next step is to sum the entire column and pivot the table :
But for the selection of the right row with your slicer on date i can't find a solution maybe you need to build a slider for all combinaison : 2016 / 2017 and 2016-2017,...

Showing October 2020 as Oct 2020 on the X axis of PowerBI Chart

I have a PowerBI Chart that I am working on for which. I got the Bars Chart on the X axis and the value for each bar in the chart is Month and Year. It is showing full months name like October 2020 but my business user wants to see OCT 2020 instead of October 2020.
Please help me how to change it
Thanks
Go to Transform data and add a column to your table with the following formula
your_new_shortname = Format (Table[Date], "mmm")
Use this new column in your visualization.
Add a calculated column on your date table and set its Sort By Column.

Relative date filter on calendar week not calculating last date of the latest week correctly

I have date dimension table and sales fact table.
Created a chart visual with date week on x axis and values as sum of salesamt.
In the filter pane added relative filter to the date. In the last 4 calendar weeks.
I have a measure that shows LASTDATE(DateTable[Date]) also on the report.
The last date is showing as 6 Feb 2021 (Saturday)
Same value when I select the latest week on x axis.
However when I choose any prior week on x axis, then the last date value is Sunday 31 Jan 2021.
Why does the current week last date show as 6th Jan 2021 (saturday) instead of 7th Jan 2021 (sunday)?
Currently, calendar week is defined Sunday to Saturday when it comes to filtering using relative dates. You can work around it by introducing additional column (basically date - 1 day) and set your relative filter on that.

Filter table based on a specific date plus 7 days

I have a table containing a date field (from 1 March 2020 to now) that I need to filter to a specific date and the previous 6 days to give complete week's data. So if I chose 30 March I'd get a table of 24 March to 30 March. If I then chose 31 March the table would show 25 March to 31 March.
I can use a date slicer to choose a range of dates but I want to be able to pick a single date, with Power BI automatically selecting the earlier date.
Any pointers much appreciated.
Mark.
You can create two measure - one for Slicer selected date and Another one with 7 day minus from the selected date as below-
Considering your date table name is- Dates
selected_date = SELECTEDVALUE(Dates[Date])
seven_day_starts_from = DATEADD(Dates[Date],-7,DAY)
Now create your calculated measure first like-
total_sales = SUM(Sales[sale])
Here comes how you will always calculate last 7 days sales considering the selected date in the slicer-
7_day_sales =
(
CALCULATE(
[total_sales],
DATESBETWEEN(
'Dates'[Date],
[seven_day_starts_from],
[selected_date]
)
) + 0
)
Remember, this is just a sample flow showing how it should work. You should try to follow the steps with your data and table structure. Dates table is a calendar table and Sales table is connected to the Dates table using the Date column.