I have two visualization below. Is there anyway to combine those two together and show user_name and service_id based another column "Type".
For examples if [type]="user", this table will show "requestor name" and "user name". if [type]="service" then this same table will show "requestor name" and "service id"
Thanks
There are at least 3 ways you can approach this.
You can create a calculated column using one of the expressions below and use this column in your visualization.
Option 1
case
when [user_name] is null or [user_name] = "" then [service id]
else [user_name]
end
Option 2
If(([user_name] is null) or ([user_name]=""),[service id],[user_name])
Option 3
You can use one of the expressions above in the category axis of your expression.
Related
i am trying to use a if formula in power query. For example, if the Column contains “guy” then value is male and the false value is “female”. I tried different ways and I can’t find the right formula to use in power query. Can anyone help me please?
If you are entering this into the Add Custom Column dialog, something like (for case-insensitive):
= if Text.Contains([Column],"guy", Comparer.OrdinalIgnoreCase) then "male" else "female"
It sounds like you are wanting to conditionally replace values in a column, based on the existing values in that column? If so, you can use the Table.ReplaceValue function in Power Query:
= Table.ReplaceValue(Source,
each [Gender],
each if [Gender] = "guy" then "male" else "female",
Replacer.ReplaceText,{"Gender"})
That will change all values of "guy" to "male', and ALL other values to "female", as you stated.
You can also leave values in place that don't meet the criteria, by simply referencing the column name instead of a specifying a new value:
= Table.ReplaceValue(Source,
each [Gender],
each if [Gender] = "guy" then "male" else [Gender],
Replacer.ReplaceText,{"Gender"})
Create a table with a column called Gender, and load it to power query. Right-click on the column header and choose Replace Values to get the UI to build your statement for you, then replace the generated code with the above modification(s) and apply to your actual requirements. The key is using the each expression to tell Power Query to test at the row value level. If you omit each, you'll see the error:
"Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?"
= Table.AddColumn(#"Changed Type","ColumnName",each if[Column] ="""Guy""" then"""Male""" else"""Female""")
I have a table with many columns. Three of these columns are:
Package Name (text)
Units Required (Int.64)
Assessment (Int.64)
What I am trying to do is to find the 'Minimum' "Package Name" first by selecting the smallest number of "Units Required", then because sometimes there are several instances where the number of required units will be the same, the row with the lowest "Assessment".
I am exploring the Table.Group() approach but I am not getting anywhere with my understanding of it. I am doing this in Power Query in Excel 365.
Psuedo Code would be something like:
Table.Group("Previous Step Name",{"Package Name"},{MIN("Units Required"),MIN("Assessment")})
As an aside - is it possible to use a single Table.Group and group at two levels? such as "Package Name" and "Column X" so that the result would be a: for each "Package Name" then for each "Column X" in each "Package Name" (nested as it were).
Thankyou in advance for taking a look at this.
Any help greatly appreciated.
Cheers
The Frog
I think you have to do it step by step.
Data
Queries
Load_Data
Load data from Excel table
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content]
in
Source
Min_Unit
Identify min unit by grouping with empty "group by" field.
let
Source = Load_Data,
Group = Table.Group(Source, {}, {{"Min_Unit", each List.Min([Units Required]), type number}})
in
Group
Min_Unit_And_Assessment
Use inner join to filter original data for entries which equal min_unit. Next, group by "units required" to get the min_assessment.
let
Source = Table.NestedJoin(Load_Data, {"Units Required"}, Min_Unit, {"Min_Unit"}, "Min_Unit", JoinKind.Inner),
Group = Table.Group(Source , {"Units Required"}, {{"Min_Assessment", each List.Min([Assessment]), type nullable number}})
in
Group
Result
Inner join to filter original data for the combination of min_unit and min_assessment.
let
Source = Table.NestedJoin(Load_Data, {"Units Required", "Assessment"}, Min_Unit_And_Assessment, {"Units Required", "Min_Assessment"}, "Min_Unit_And_Assessment", JoinKind.Inner),
RemoveUnnecessaryColumns = Table.RemoveColumns(Source,{"Min_Unit_And_Assessment"})
in
RemoveUnnecessaryColumns
Result
Qualia, thankyou for pointing me in the right direction.
The way that I solved this was really simple in the end!
Step 1: Sort the rows based on the grouping criteria (package name, system class) in that order
Step 2: Add an Index Column so each row has a unique ID to work with
Step 3: Group the table based on the same fields (package name, system class) and 'aggregate' on the lowest Index Number (MIN)
Step 4: Perform a 'Merge Queries' with a Left Outer Join using the Index Number as the matching field between your current 'step' and the step from earlier in the processing where the Index was added - you can then have the rows matched and only the rows needed will be matched since the others are now gone due to the MIN aggregation from earlier. Here is my example:
Table.NestedJoin(#"Grouped Rows", {"Winner"}, #"Added Index", {"Index"}, "Lookup Data", JoinKind.LeftOuter)
- Grouped Rows was the grouping step (Step 3)
- Winner is the name of the Index that had the minimum value
- Added Index was the last step before grouping that still had all the columns (Step 2)
- Index is the column that was added after the sort to uniquely number each row
Step 5: Expand the table and select the columns of data that you want to hang onto
Treating it a bit like a database was a good approach and I appreciate the suggestion you put together for me. Hopefully this will allow others to solve some of their problems too.
Cheers and many thanks
The Frog
I have Bar chart with values colored by 2 different filters.
What I need is to rename each combination of the 2 filters into just one name.
i tried to write it with CASE expression but with no luck.
below screenshot, shows what is required.
Any ideas ?
Screenshot sample : Motor Type
Why did you case expression not work?
Something like that should work:
<CASE [COLUMN] WHEN "VALUE1" then "Category A" WHEN "VALUE2" then "Category B" ELSE "Category C" END>
But in your situation I would do
<if([column 2] in ('SALA','SUPP'),'Motor category A','Motor category B')>
Add this expression here (right click > custom expression) :
As the title states, I am trying to do a merge of 2 tables. I want a nested joint where the values from the first table are always there and rows matching the second table are added to the first. I believe this is known as the nested join.
Unfortunately, it only allows for 1 key to 1 key matching where as I need it for 1 key in table 1 to 2 keys in table 2
Here is an example
Table1:
Group
..
..
Time
Date
Table2:
Group 1
Group 2
..
..
..
Other Info
What I want is where "Group = Group 1 OR Group = Group 2" and display the matching row from table 2 nested into Table 1
I looked at the following example but I must be confused by the syntax because it doesn't seem to be working for me.
How to join two tables in PowerQuery with one of many columns matching?
So after further investigation of the answer post I linked earlier, I will add an explanation of it here:
Table.AddColumn(Source, "Name_of_Column",
(Q1) => Table.SelectRows(Query2,
each Q1[Col_from_q1] = [Col_from_q2] or Q1[Col_from_q1] = [2_Col_from_q2]
)
)
So this did work for me and it adds an extra column that needs to be expanded to get all the values from the table. What i would add is that I don't know / haven't tested if there are multiple matches and how it treats it, based on nestedjoin, I would assume that it will duplicate rows in the first table.
i am currently trying to filter a report containing business trips and itineraries so it shows only those that have at least one business stop abroad.
In more general terms, i want to show all data for a specific value in column "Itinerary Key" if in one of two other columns "Departure Country" OR "Arrival Country" a certain condition ("<> Country") for the information connected to the value in column "Itinerary Key" is met.
So far i created a Query Calculation item ("[Itin Key if Trip abroad]") containing the expression:
CASE WHEN
([Departure Country]<>[Country]) OR ([Arrival Country]<>[Country])
THEN [Itinerary Key]
ELSE Null
END
So i have a column that contains the Itinerary key, but only in the lines where the condition is actually met.
I then created a filter with the following expression:
[Itinerary Key] in ([Itin Key if Trip abroad])
The idea here was to have a selection based on matching the itinerary key with the pool of itinerary keys that meet the condition on any line. However, it still only shows the lines where the Query calculation item actually generates a value.
I want to show all the lines for the columns "Departure Country" and "Arrival Country" for each Itinerary Key where the condition from the query calculation is true at least once.
How can this be done?
I think you can accomplish by using this filter instead of the one you mentioned:
count([Itin Key if Trip abroad] for [Itenerary]) > 0
For every unique itenerary key we will count the non-null values (nulls are ignored in counts). If a specific itenerary has no rows that match the criterion, the count will return 0 and its rows will be excluded. If a specific itenerary has one or more rows that match the criterion, its count will be 1 or more and all rows for that itenerary will be included.