replicating the tableau report into power BI - powerbi

I am trying to replicate one of the tableau report into power bi. I am new to tableau and power BI so I am just learning from online and working on this project. Hence I have few questions in adding filters and grouping columns.
there is a custom query used in tableau to build the report. I am using the same report in power bi to replicate the same report. I have attached the code below. I have loaded the query in power bi and visualize the data. but I wanted to add the filters same like the tableau report has. but I am unsure how to add those in power BI.
Questions 1 : how do I add the filters to the power bi in a same way it is used in tableau(screenshots attached)
questions 2: in tableau filter "report date" is used a condition (report date >=adddate and reportdate<=dropdate. could you please help me how to create the same type of filter in power bi?
3. how do I group by the columns in power bi in the same way as tableau does?(screenshot attached)

Good you are trying to learn Power BI and tableau, two really great tools! I'm not going spoil your learning by precisely answering your questions, but I can give you some directions.
Try using the slicer visual and in the visual select drop-down.
This one is a bit more complicated in Power BI as it requires you to create multiple objects. First you should create a list of values for your parameter. You can do this using Create New Table and using the CALENDAR() function, it's called a calendar table. Combine it with a MIN() and MAX() function to get the first and last dates in your dataset.
Parameter = CALENDAR( MIN ( Table[adddate] ) ; MAX ( Table[dropdate] ) )
Secondly, you create a measure which will determine if a row in your table matches the criteria you specified. This needs to be a measure, as calculated columns do not accept variable parameters.
Included =
var _selectedDate = SELECTEDVALUE( Parameter[Date] ; MIN ( Parameter[Date] ) )
RETURN
SUMX (
Investments ;
IF (
AND ( Table[adddate] <= _selectedDate ; Table[dropdate] >= _selectedDate )
; 1
; 0
)
)
Add the measure to the visual filters of your matrix and make sure it filters for the value 1.
Finally, add the Parameter[Date] field to your report page and set it to the visual style slicer as mentioned in the answer to question 1
Try the matrix visualization and make sure that you drill down in the visual. Hover your mouse over it and select the branched arrow.

Related

Slicers showing all values - Power BI Desktop

I have a table in Power BI Desktop which has multiple columns (5 Dimension data connected with a Fact table - Star Schema).
I have now added 3 Slicer to filter data in above table but when I select the first slicer then the other slicers should show only available dimensions data but it is showing all the available data.
I tried changing Cross filter Direction to both from single in Manage Relationship but it works for only one column but not to all with the below error or warning message.
NOTE: I do have few more Pages in the same Visualization report which contains separate fact table with same dimension keys.
Please let me know how to resolve this or any other suggestions.
Use the following measure to filter through your dimensions
Cross Filter = INT( NOT( ISEMPTY( 'Your FACT TABLE') ) )
Then dragg this measure in every slicer into the filter pane and select the option is equal to 1.
My power bi version is in spanish but you will get the idea.
----------------------------------------

Power BI DAX | Multiple Slicers from Different DIM TABLES with Multiple ALLSELECTED DAX statements

Is there a way to to write ALLSELECTED DAX with multiple slicer values where slicers come from different Dim Tables?
Goal: A Table in Power BI where end users can select the external slicers filtering a table and see the sum cost based upon the 3 above mentioned external slicers. See picture below.
Example:
Slicer 1 has Project Name (DimProject[ProjectName])
Slicer 2 has Project Manager (DimTeam[ProjectManager])
Slicer 3 has Calendar Year & Month (DimDate[CalendarYearAndMonth])
I tried the following: CACULATE(SUM(COST), ALLSELECTED(DimProject[ProjectName]), ALLSELECTED(DimTeam[ProjectManager]), ALLSELECTED(DimDate[CalendarYearAndMonth]) )
It didn't work. Can anyone advise on what is the correct way to filter with multiple slicer values [from different tables] while using ALLSELECTED? Is there a better pattern I should be using?
Have a look at the TREATAS function
https://learn.microsoft.com/en-us/dax/treatas-function

Power BI - DAX query to remove duplicated rows in SUM calculation

My scenario is this: SalesValue have been entered for multiple sessions namely Lunch, Breakfast, dinner which is grouped by SessionKey in numbers. The same SalesValue repeats at times for 2 or more sessions for a given production plan date, based on MenuKey, RawMaterialKey and IngSFKey.
I need to use DAX query in Power BI to remove duplicated SalesValue based on ProductionPlanDate and SessionKey for a particular MenuKey in a given date.
I have attached the screenshot of a sample value range of SalesValue containing duplicate values for the same date across different sessions for your reference. For example, rows 7 and 14 have the same ProductionPlanDate, SessionKey, MenuKey, and SalesValue.
So you have a table with one "Grain" and you want to change the "Grain" by using a subset of the columns. Specifically you want only rows with distinct columns ProductionPlanDate, SessionKey, MenuKey and SalesValue
To do this in a DAX query you would use
evaluate
summarize
( 'table name'
, 'table name'[ProductionPlanDate]
, 'table name'[SessionKey]
, 'table name'[MenuKey]
, 'table name'[SalesValue]
)
You could provide this to create a calculated table or provide it to each measure that needs to work with this coarser grained data set.
However as it seems you are in Power BI the more appropriate place to do this would be to create your coarser grained table using Power Query (via the Edit Queries section of Power BI).
This is better than doing it in DAX as DAX is more tuned to analytics where Power Query is tuned to data transformation - and you want to do data transformation.
You can either keep the table that you have now alongside the new modified or replace it accordingly.
option A will just change your incoming table to have the new coarse grain.
option B will keep your original table and have the new grained table alongside it. Note that this will mean any Power BI visuals that you have created will need to be "rewired" to use the new table.
To do the transform in Power Query, the steps for both options are
Go to the Edit Queries area on PowerBI
Select the columns that you want to create the new Grain (i.e. ProductionPlanDate, SessionKey, MenuKey and SalesValue) by holding ctrl and clicking the column headers of each column in turn.
Right click on the column header for one of the selected columns and select "Remove Duplicates"
If you want option B, simply first copy the existing table by using "Reference" then do the same thing as follows:
Find your existing table on the left Queries section, r-click and click Reference
Rename the new table something appropriate
Apply the transform steps to the new table as above
Click Close & Apply and rewire any existing visuals that you need to use the new table
If you find you don't need your old table you can R-click on it in Power Query again and uncheck "Enable Load" so that PowerBI will not see it anymore.

Based on slicer selection create dynamic calculated table in Power BI

I’m new to Power BI. Currently facing similar issue explained below in my product development.
I have created power bi modle with below dimensions and facts from adventureworksDW.
Then I created a calculated table, which gives result as sum of sales group by ProductSubCategory and ProductCategory. Below is the DAX for the calculated table.
Now I want to create a new calculated table, which gives me TOPn ProductSubCategory based on the Total sales amount.
Below is the DAX to do this.
and model relationships looks like below.
I want this TOPn rows to be displayed based on filter condition on product category. Something like below.
This works fine when I hardcode the product category value in the DAX itself. But if I want to change this product category values from the slicer selection, then I didn’t get any results.
What you are asking for is not possible as Power BI is currently designed. Slicers cannot affect calculated tables. Calculated columns and calculated tables are evaluated once when the data is first loaded and are static until the data is refreshed.
However, you can get the table visual you want in a much simpler manner by writing the appropriate measure and putting that in the table instead of defining an entirely separate table.
TotalSales = SUM(FactInternetSales[SalesAmount])
The Top N filtering is available in the visual level filters settings.
You can simply use the SELECTEDVALUE function as shown below.
var __SelectedValue = SELECTEDVALUE('ProductSales'[EnglishProductCatogaryName])
return
Filter(
'ProductSales',
'ProductSales'[EnglishProductCatogaryName] = __SelectedValue
)
)

Power BI create column with condition

My direct Query structure img
I want to create a column in FB_DATA_AD_ONLY to get the VALUE of FB_ACTION_AD where the ACTION_TYPE="something" in power BI. I should keep the function " direct query". Do you think I can do this in Power BI ?
First, I would suggest looking at these site to understand the limitations of Direct Query (I know that I don't know all of the limitations).
Use DirectQuery in Power BI Desktop
Using DirectQuery in Power BI
Second, in the first one, it talks about a setting you can turn on to bypass some of the limitations Power BI imposes on Direct Query. To turn that option on, go to File -> Options and settings -> Options, then go to Direct Query and check the box next to Allow unrestricted measures in DirectQuery mode (Power BI will need to be restarted after checking that option).
With that option checked, you can create some new measures in the data. I have some basic sample data (created using this SQL script).
Click on the ellipses ("...") next the your FB_DATA_AD_ONLY table (I'll be using my Buildings table) and select New measure. Enter the following formula
NewMeasure = CALCULATE(
SUM(FB_ACTION_AD[VALUE]),
FILTER(
FB_ACTION_AD,
FB_ACTION_AD[ACTION_TYPE] = "something"
)
)
I used this formula.
EmpSum = CALCULATE(
SUM(Employees[idemp]),
FILTER(
Employees,
Employees[FirstName] = "Alex"
)
)
I threw together a quick table and matrix to illustrate that the measure is returning the expected value (Alex is only assigned to one building and their ID is 2, so that building would have a EmpSum value of 2).