Maxtrix - How to move columns to rows - powerbi

I have a Maxtrix that looks as follows:
And the Visualizations pane looks as follows:
Sales, COGS, GP and GP% are fields in a dataset. The YearMonth field is a field from another dataset.
What I want is for Sales, COGS, GP and GP% to be rows and my only column should be year-month. So I would have a row for Sales and totals for each year and month. And then another row for COGS and totals for each year and month etc. I can't find an easy way to do this because Sales, COGS, GP etc. are not like categories contained in another dataset, linked to this dataset that I could drag to Rows in the Visualization tab.

There is a setting for this. Go to the Format tab and turn on 'Show on rows' under the Values section.

I would first create a table using Enter Data e.g. All Measures containing 1 column (e.g. Measure Name) and 4 rows, containing Sales , COGS , GP, GP%.
Then I would create a Measure using the SWITCH function, e.g.
Any Measure = SWITCH ( 'All Measures'[Measure Name] , "Sales" , [Sales] ,"COGS", [COGS] , "GP" , [GP] , "GP%" , [GP%] )
Then I would add 'All Measures'[Measure Name] to the Rows well, and replace the Values well with Any Measure.
You may need to enhance that to get the numeric formats right, e.g. by wrapping each measure reference in a FORMAT function.

Related

PowerBI - Calculate average year from a date column

I have a table (we'll just call it MyTable) in PowerBI that includes a Date column. I have created a DateDimension table using CALENDARAUTO() with columns for the Date, Month#, MonthName, etc and created the relationship between that Date and the Date in MyTable.
I want to calculate the average year based on the records in MyTable. For example, if I have records with 1/1/2005, 1/1/2014, and 1/1/2015, the average year should be 2011.
How would I go about doing that? I've tried doing a measure of AVERAGE(DateDimension[Year]) and adding that to a Card visual, but it just shows 2.01K. If I do FORMAT(AVERAGE(DateDimension[Year]), "####"), the average is completely wrong.
Since you already have this DateDimension table, use
Average =
AVERAGEX(
MyTable,
RELATED(DateDimension[Year])
)
You can control the formatting by clicking on the measure (Average) and then using the Measure tools pane:
Set it to Whole number and no thousands operator.

Multiple operators in DAX

Scenario: I have multiple columns in a table e.g. customer ID, customer Name, City, Invoice amount, paid amount.
I want to create a slicer based on invoice amount, where I can filter the data based on invoice amount column as below:
Amount 5000-200000 - Slicer Option should show text "Low"
Amount 200000 - 1000000 - Slicer Option should show text "Medium"
Amount 1000000 - any higher amount - Slicer Option should show "High"
I tried using Dax If ( or ( ... ) ) but it is not working.
Since I am new to Power BI so don't know if I should create a measure a column or a table.
Thanks in advance
You can create a "New Column" in the Table, using "Table tools":
Introduce this code:
AmountType = if(Table[Amount]>1000000,"High",if(Table[Amount]<200000,"Low","Medium"))
Then use AmountType in the slicer.
Note that if you need to exclude those with Amount < 5000 from the category "Low" you would have to add it to the if statement:
if(AND(Sheet1[Amount]<200000,Sheet1[Amount]>100000),"Medium","Low")

DAX Calculate Sum of sales per productid filter by productid ( NOT IN TOP 20 )

I am fairly new to PowerBI DAX and I want to filter out the top 20 product ids in a measure.
I came up with this formula but it does not seem to be working and I was hoping to get some help here.
$ Amount Parcel =
CALCULATE(
SUM(Data[$ Amount Parcel]),
FILTER (Data, NOT (Data[idProduct], SUM(Data[NetSales])) IN TOPN(20, SUMMARIZE(Data, Data[idProduct], "NetSales", SUM(Data[NetSales]))))
)
I want to show sales per PID for all products except for our 20 best sellers.
Thank you !!
I would suggest an easier approach adding a dimension column.
First of all, you need to have Product dimension table separated from Sales fact table. Make sure to create one-to-many relationship between Product and Sales with "Single" cross filter direction.
Then you can create a calculated column on Product table, which can be used to filter out top selling products.
Sales Rank = RANKX('Product', CALCULATE(SUM(Sales[SalesAmount])))
Now drag and drop Sales Rank field into the Filters pane of your visualization, and set the filter condition so that top selling products will not be shown.

How to add Filter to Slicer to display the calculated Measure based on selection using Power BI

I am totally new to Power BI and struggling with Slicer. I have the below requirement:
I have 4 columns Starting From, Destination, Distance KM. For this, I need to add a slicer. If the user clicks on Distance KM, then the chart has to be updated with Distance KM values. Now here comes the trick. I also want to display a column Distance in Miles based on the Distance KM calculation(the KM has to be displayed in Miles). So, whenever user clicks on Distance KM(in slicer), it should show the chart with KM data, if the user clicks on Miles(in slicer), then the chart should be populated with Miles information. I need to do this using slicer in power bi. Trying to achieve this since a while but couldn't get through it.
Please help me out
You only list three columns after stating your data has four, but I believe this should work:
You need to create a new table for the slicer. Within the Home tab select "Enter Data". Enter the values you want to be able to select from (I named the table DistanceSlicer). Load that table and create a slicer with it.
Now you can create a new measure based on this slicer selection. Within the Modeling tab select "New Measure".
SelectedMeasure =
IF (
VALUES ( DistanceSlicer[Measure] ) = "Kilometers",
SUM ( Table1[Distance KM] ),
SUM ( Table1[Distance Miles] )
)
Now use this measure in your table/chart and it should update based on your slicer selection.

Power bi - Use Slicer selection in filtering data

I am new to Power bi but i want to use Slicer(user selection) while filter data with comparison by 'Greater Than' instead of equal to.
I have data of devices with LastUpdated date column. and slicer with few list of dates for 15 days gap (calendar would be better but as it is not available yet sticking with dates list)
When user select a date in Slicer i want to filter the data whose Lastupdated Date is greater than equal to selected date. How to achieve this? tried columns,measures..
Any help is appreciated.
I think you can create a measure that links the Date list table and the Device table, even if there is no relationship between them. However the measure must be present in your visualization otherwise the slicer will not affect it.
I've created a measure that calculates the maximum date for those rows which last update date is greater or equal than the slicer selection.
CalculatedLastUpdate =
CALCULATE (
MAX ( DeviceTable[LastUpdate] ),
FILTER (
DeviceTable,
DeviceTable[LastUpdate] >= MINX ( DateList, DateList[Date] )
)
)
DateList - a table containing a column [Date] with you date range.
DeviceTable - a table containing device data.
Now you can delete LastUpdate column from your visualization in order to avoid two columns with the same data.
Let me know if it helps.
I don't know about earlier , but now you can modify the date slicer to do as "after" the given date (you can do so by clicking on the icons present in the rightmost side of the slicer visual itself , wher you can select mode of slicer as between , after ,list , dropdown etc.)...which I believe means that you get all data for dates greater than the selected dates for the given column used in slicer which in your case will be LastUpdate.