Dax - grouping data for Sankey Chart in Power Bi - powerbi

I am trying to group my data based on the column "Type" and prepare a sankey chart with Country data.
The desire results is to have value by country for type - "MLA" and value for country for type "Sponsor". The tricky part is that there is a lot of duplicated information and it needs to be by unique ID.

You could look into potentially using the GROUPBY function:
https://learn.microsoft.com/en-us/dax/groupby-function-dax
You would add this to a blank table, and then it would create a summarised version of the original data table but summarised into the columns that you choose.

Related

How to make a summarize table reflecting the filtered calculation from visualization filtes/slicers?

I'm new to Power BI. I have 2 tables ('patient_info' and 'rating_table') which are related to each other 1:1 by the "id" key. I created another summary table ('rating_by_doctor') which groups the ratings among each doctor and calculate the mode for each of them. The DAX expression I used to get the summary table are as follow:
rating_by_doctor =
SUMMARIZE(
rating_table,
patient_info[doctor],
"mode",
MINX(TOPN(1,ADDCOLUMNS(VALUES(rating_table[rating]),"Frequency",CALCULATE(COUNT(rating_table[rating]))),[Frequency],DESC),rating_table[rating])
)
The tables look like this
However, when I try to add this table into a visualization, and apply a filter/slicer on it (eg: the [gender] column in 'patient_info'), it has no effect to the summary table at all. I want the visualization of the summary table reflects the change of the underlying aggregated calculation based on the current filter/slice, may I know how can I achieve this please?

Create Rows to the table where the data is missing for specific dates in power BI

I have a table with below columns in my dataset. We have monthly revenue for each resellers in this table.
For few resellers, there will be no data for some particular months, as they didn’t generate revenue on those months. I want to create rows for those resellers with the missing date and the revenue for those missing dates to be updated as blank.
Please advise how we can achieve this.
Current data:
Expected result:
For the missing dates you need to create a date table using the CALENDAR function like this:
Date table = CALENDAR(MIN(Date), MAX(Date))
This will create a table with a single colmn containing all the dates in your table with filled gaps (even if you don't have certain dates in your table). Then you need to create a relationship between your table and the date table.
When you use the date and the revenue in a visual lets say table or matrix all dates will be visible but the revenues will be blank (except for those that actually had a value in revenue).

Power Bi Extract a Column value based on some another field in different Table

I have a Power BI table with some columns as given below:
Table1 - Columns(Project, Program, Name, Attribute, ID)
Example of table1:
Now I have a different measure which is used to view Power BI report. It also has some fields as given below:
Measure1 - Columns(Project, Name, Attribute, and few more)
Example of Measure:
Now I want to add ID (which is available in Table1) as Measure1 is being used to view report. How can I display ID based upon Name and Project.
Can anyone guide or help how to solve it?
If you can do this in your source Database using left join between this 2 tables.
If not, then you can use virtual relationship in DAX:
Display_ID = CALCULATE(min(Table1[ID]), TREATAS(VALUES(Table1[Project]), Measure1[Project]), TREATAS(VALUES(Table1[Name]), Measure1[Name]))

Power BI - Filter table using slicer to match within concatenated column

I've looked all over and can't find a way to do this.
In the table, I have all postcodes throughout the UK and a calculated column that concatenates from another table the products' that have been purchased in that location.
I need to filter the table to hide rows where the value selected in the slicer is in the concatenated column. I think this needs to be a measure and have tried using CONTAINSSTRING but nothing seems to be working.
Latest measure that I have tried is:
=IF(CONTAINSSTRING([Concatenated Values],[Selected Slicer Value]),"Hide","Show")
Does anyone have any ideas?
Example tables and expected results:
You can link the "another table" (the one with the products (not concatenated) per area) to the Area table.
Just change the filter option to: cross-filter direction: both
Then you can use it in your slicer.
Follow these below steps to achieve your requirement.
Let-
Your Slicer Table name: Table1
Your Details table name: Table2
Step-1: Create this following measure in Table2
show_hide_this_row =
FIND(
SELECTEDVALUE(Table1[products]),
MIN(Table2[products]),
,
0
)
Step-2: Add visual level filter using measure "show_hide_this_row" as below-
The output will be as below-
This functionality only works perfect when single selection is enabled in your slicer.

Create table comparing Two Queries with identical fields/field names

I would like to create a table to compare Month To Date (MTD) Vs YTD Sales data metrics
I am using two queries:
1st query = YTD Sales data (Two fields: Sales and Quotes)
2nd query = MTD Sales Data (Two Fields: Sales and Quotes).
Each query has the same field names, just different data
I would like to output a table like the following
How to I create the above table? At the moment I can only create a table like the following:
The latter 1x4 table only works if I appropriately name the fields. But definitely isn’t what I want, because with enough fields, the table could go on forever.
Any help would be appreciated
In the query editor, create a label column for each table that labels what they are and then append the two tables together so you get something like this:
Then you can create a matrix visual with the Label column in the Columns field and the Sales and Quantity columns in the Values area.
Make sure you've switched "Show on Rows" to "On" under the Format > Values section of the Visualizations pane.