Visualization in Power BI - powerbi

I am new to Power BI Desktop and Power BI Query. The left part is the data, and the right part is my desired output in Power BI. I tried to use the Matrix Report Visual to format my data like the table on the right, but it only allowed me to select the Product column in the row. I hope to get the desired output without creating separate tables for each quarter.

You could bring your data into powerquery, and use this code to transform the data. You'd have to modify it to show your actual table name (Table1) and the name of the columns as appropriate. It basically groups on index/product to find the most recent target sale, expands the data back, then pivots to get the sideways view
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"index", "product"}, {
{"data", each _, type table },
{"most_recent_target_sale", each Table.Sort(_,{{"time", Order.Descending}}){0}[target_sale], type number}
}),
#"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"time", "sale"}, {"time", "sale"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded data",{{"index", type number}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[time]), "time", "sale", List.Sum)
in #"Pivoted Column"

Related

Power BI Count/Sum Based on Multiple Columns

I'm trying to count and sum based on multiple columns. When I tried the "group by" function in transform data, it gives me a timeout error.
Below is an illustrative example of what I'm trying to do. In the real dataset, the number of columns is 30+ and the number of possible entries in each column is also large, resulting in many unique combinations.
I'm not sure if there are other functionalities in Power BI that can achieve this, please send help!
Have this:
Want this:
Im going to go ahead and guess that perhaps you want to sum all your columns without knowing how many of them you have, and this code can work on any number of columns, grouping the first two
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Column1", "Column2"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"Column1", "Column2", "Attribute"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"SUM", each List.Sum([Value]), type number}}),
#"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[Attribute]), "Attribute", "SUM", List.Sum)
in #"Pivoted Column"
In Power Query, on the Tranform ribbon, click "Group By" and enter these settings.

how to create a DAX measure / power query process / which returns a value from another row, which has the same date & time

Please find below links to the Fact table and the overview of all tables. I would like to create a DAX measure, or new column in the Fact table ("transactions"), where:
The currency is NOT equal to EUR (e.g. "BTC"),
Giving the value equal to a opposite value of "amount", as given in the row with EUR as currency (e.g. +5. Positive for negative and vice versa),
Where the date and time of the two rows (EUR and non-EUR) have the same values (e.g. 03/11/2021 and 12:28:06)
The "type" = "trade",
In all other cases, I think it would be best to give a value of 0.
In my Fact table screenshot, I manually added the EUR_amt column in Excel to show what I would like to create
I think it's also possible to add the column, then group by time and date, such that the rows with EUR as currency with EUR_amt being 0, would be removed. All using power query. That would be even better.
(The "Currencies" table just uses the distinct values of the "currency" column in the "transactions" table, via PowerQuery. Not relevant for this question I think)
Many thanks in advance!
-YK
Fact table "transactions"
Overview of tables
Calculated Column:
EUR_amt =
IF (
OR ( transactions[type] <> "trade", transactions[currency] = "EUR" ),
0,
- LOOKUPVALUE (
transactions[amount],
transactions[Date], transactions[Date],
transactions[Time], transactions[Time],
transactions[currency], "EUR",
0
)
)
Here's one way to do this using just Power Query and the Advanced Editor
Group by data and time
Generate a custom column for each subtable based on your rules
Expand the subtables, remove those with "0", and re-order the columns
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"type", type text}, {"currency", type text}, {"Date", type date}, {"Time", type time}, {"amount", type number}}),
//Group by Date and Time
#"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "Time"}, {
//Add the Eur amt column to the grouped table
{"EUR_amt", (t)=>let
//determine relevant euro amt for each sub table
eur= t[amount]{List.PositionOf(t[currency],"EUR")},
//add the column to each subtable basaed on conditions
addCol = Table.AddColumn(t, "EUR_amt",
each if [type]= "trade" and [currency]<>"EUR" then -eur else 0)
in
addCol}}),
//Expand the new table
//Filter out the 0's
//reorder the columns
#"Expanded EUR_amt" = Table.ExpandTableColumn(#"Grouped Rows", "EUR_amt", {"type", "currency", "amount", "EUR_amt"}, {"type", "currency", "amount", "EUR_amt"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded EUR_amt", each ([EUR_amt] <> 0)),
#"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows",{"type", "currency", "Date", "Time", "amount", "EUR_amt"})
in
#"Reordered Columns"

Group By a column based on multiple other columns - Power Query

Hello beautiful people,
Could someone please help me with my below request, (noting that I am working with Power Query Editor). So I need it to be done using creating conditional columns in power query maybe?, please help.
I need to group users in a table based on a category with showing their count in multiple different fields, As per the below example:
I need results to be:
Muuuuuuuuch Appreciated
In powerquery, try this
Click select period and name columns
Right click, unpivot other columns
Click select period, attribute and value columns
Right click, group ... new column name Count, operation Count rows
Click select attribute column. Transform ... pivot column... values column Count, Advanced options, do not aggregate
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Period", "Name"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"Period", "Attribute", "Value"}, {{"Count", each Table.RowCount(_), type number}}),
#"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[Attribute]), "Attribute", "Count", List.Sum)
in #"Pivoted Column"
Alternately,
Click select period and name columns
Right click, unpivot other columns
Right click name column and remove
Right click value column and duplicate
Click select attribute column .. Transform pivot column ... Values column:Values Copy
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Period", "Name"}, "Attribute", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Name"}),
#"Duplicated Column" = Table.DuplicateColumn(#"Removed Columns", "Value", "Value - Copy"),
#"Pivoted Column" = Table.Pivot(#"Duplicated Column", List.Distinct(#"Duplicated Column"[Attribute]), "Attribute", "Value - Copy", List.Count)
in #"Pivoted Column"
Neither one is going to put in a blank row for a combination that does not exist like Dec No. Thats more complicated if required

Slicer to search for a specific string in a column - Power BI

I have two tables.
Table1
Category
A
B
...
Table2
Companies | Indistries
1 | A,D,X
2 | Z,B,X
3 | N,D,R,B,Q
I would like to have a slicer with different categories (A-Z). When clicking A all Diagrams should be filtered according to the Companies that "contain" industry A.
Long story short: it would be like a normal relationship but instead of finding the same, it would be a "contains".
Thank you for your help! Really appreciated.
Please down load the sample report file from link - HERE
Follow-
Created a Index column in table your_table_name
Created a new table slicer_new with this below code-
let
Source = your_table_name,
#"Split Column by Delimiter" = Table.SplitColumn(Source, "Indistries", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), {"Indistries.1", "Indistries.2", "Indistries.3", "Indistries.4"}),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Indistries.1", type text}, {"Indistries.2", type text}, {"Indistries.3", type text}, {"Indistries.4", type text}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Index"}, "Attribute", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"})
in
#"Removed Columns"
Here below is the final output of slicer_new table-
Get back to report and check the relation between table your_table_name and slicer_new.
Create slicer from table slicer_new
Add table visual for column Indistries from table your_table_name
Now select value in slicer, everything should work as expected now.

Dynamic select latest date column in Power BI

There is a scenario as attached excel file, an issue progress daily tracker.
In Power BI, if I use a table visual, and want to only show the latest update(in this case will be 11/30/2018), how could I let it be done auto instead of selecting the date column manually?
You'd be better unpivoting that source data and storing the date as a value of a "date" column, rather than having separate columns for each date. Then you can use all the DAX time intelligence functionality.
You could use a query like this, to normalise your source data:
let
Source = MyTable,
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"#", "Issue", "Owner"}, "Date", "Value"),
#"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"#", Int64.Type}, {"Issue", type text}, {"Owner", type text}, {"Value", type text}, {"Date", type date}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Value] <> null and [Value] <> "")
in
#"Filtered Rows"
Now your table view can be filtered using the Date field - if you want the latest date, then a Top 1 by Latest Date filter would work: