Hiding/obfuscating all but one legend on the x-axis - powerbi

Let's say I have a table listing employee names, certain performance aspects and scores, something like:
Name | Measure | Score
Alice| A | 10
Alice| B | 5
Alice| C | 7
Bob | A | 8
Bob | B | 5
Bob | C | 4
Carol| A | 6
Carol| B | 8
Carol| C | 7
This data is presented in a simple stacked column chart:
What I would like to do, is to find a way to hide all but one the x-axis legends (Name - Alice, Bob, Carol) depending on which name is selected from the slicer above.
So say Alice is selected, only her name would be displayed, the other columns would still be there but without their corresponding names, something like:
Selecting Bob would hide the other two names etc.
Any help would be appreciated

Here you go.
You need to create 3 additional columns as follows.
My code for these is:
Alice =
SWITCH(TRUE(),
'Table'[Name] = "Alice", "Alice",
'Table'[Name] = "Bob", UNICHAR(8203),
'Table'[Name] = "Carol", REPT( UNICHAR(8203), 2),
BLANK()
)
Bob =
SWITCH(TRUE(),
'Table'[Name] = "Alice", UNICHAR(8203),
'Table'[Name] = "Bob", "Bob",
'Table'[Name] = "Carol", REPT( UNICHAR(8203), 2),
BLANK()
)
Carol =
SWITCH(TRUE(),
'Table'[Name] = "Alice", REPT( UNICHAR(8203), 2),
'Table'[Name] = "Bob", UNICHAR(8203),
'Table'[Name] = "Carol", "Carol",
BLANK()
)
Insert a new field parameter as follows.
Create your chart as follows.

Related

How to enhance performance of tables combination?

I have a list of tables (in actual data) with different columns for which, after to combine, I get a table of 15 columns. In actual data, the list of tables is get from several previous steps and each step takes less than a second, but only Table.Combine() takes almost 2 minutes with an input of about 1200 rows. In order to show the example, I show below an output of 4 columns only,
Is there a faster alternative way to get the same output given by Table.Combine()? Thanks for any help.
This is the code of the query I has so far.
let
Tables = {
Table.FromRecords({[Name = "Bob", Phone = "123-4567"],
[Name = "",Phone = ""]
}),
Table.FromRecords({[Fax = "987-6543", Phone = "838-7171"],
[Fax = "", Phone = "233-687"],
[Fax = "", Phone = "544-778"]
}),
Table.FromRecords({[Cell = "543-7890"],
[Cell = ""],
[Cell = ""]
})
},
CombinedTable = Table.Combine(Tables)
in
CombinedTable
The current output is:
UPDATE
This is the entire query, with Table.Buffer() added in step group5
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jVNdb4JAEPwvPFty3KHUR1C4Sg+0x5lqqSF+tGlqH5q0mv787hkal41FEsLNLjczu5NQlk6kpqP7yixnceU5Pad+Vr3SCQF4qI4A9FE9AiBQXcyj6qTWlBkDYKiOSd1C8wkNTyPpdK174DntHpzscUucB8R5iOqE6rU6B1ecOXEeEueOUXmE5nejBS1uCZHt6C5JnCge3mReiiMLJ/mNELidARgZreMCNTWAsQozPMgC0N2DFbHK8unUTTOr9XxgTGzzuVIn9AKtRZrDe7M5uod3xrj7uf8I2MD9Or7u1t9rxA2VmsJRGIPui//vX/CK8rOX7zHLFXBgbntM9L+T01koSUaRnvQNiciEanw1Ir37gSLZ7mx/Uw/qcbFvDKjjFD7Bijq1Eywf64uC87egWwzS/xP3hmfG6hc=", BinaryEncoding.Base64), Compression.Deflate)),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [COL1 = _t, COL2 = _t, COL3 = _t, COL4 = _t]
),
fx = each not List.IsEmpty(List.RemoveItems(_,{"",null})),
group0 = Table.Group(Source, "COL2", {"n", each _}, 0, (x, y) => Byte.From(y = "" or y = null)),
group1 = Table.TransformColumns(
group0,
{
"n",
each
let
a = Table.Skip(_),
b = Table.FirstN(a, each [COL3] = "" or [COL3] = null),
c = Table.Skip(a, Table.RowCount(b))
in
[a = a, b = b, c = c]
}
),
group2 = Table.TransformColumns(
group1,
{"n", each Table.ToColumns(Table.Transpose([b])) & Table.ToColumns([c])}
),
group3 = Table.TransformColumns(group2, {"n", each List.Select(_, fx)}),
group4 = Table.TransformColumns(group3, {"n", each Table.FromColumns(_)}),
group5 = Table.Buffer( Table.TransformColumns(group4, {"n", each Table.PromoteHeaders(_)}) ) ,
combine = Table.Combine(group5[n]),
Custom1 = Table.SelectRows(combine, each fx(Record.ToList(_)))
in
Custom1
The purpose of this query is to tabulate data that appears in repeated blocks and subblock in the way I show below.
This is the output given by the query.
No, but try wrapping the initial table definitions as you go along in Table.Buffer()
let
a= Table.Buffer(Table.FromRecords({[Name = "Bob", Phone = "123-4567"],[Name = "",Phone = ""]})),
b= Table.Buffer(Table.FromRecords({[Fax = "987-6543", Phone = "838-7171"], [Fax = "", Phone = "233-687"],[Fax = "", Phone = "544-778"]})),
c= Table.Buffer(Table.FromRecords({[Cell = "543-7890"],[Cell = ""],[Cell = ""]})),
CombinedTable = Table.Combine({a,b,c})
in CombinedTable

Group Items in Comma Separated values in Dax

I have following DAX code. I need comma separated holiday list based on Week No . I tired with CONCATENATEX function and it combine all comma separated holiday list in each row instead of week wise. Any one have any idea how we can achieve below expected using DAX.
Dax Code:
DEFINE
VAR A = UNION( ROW ("WeekNo", 1, "USAHoliday", "New Year", "CANHoliday","New Year")
,ROW ("WeekNo", 16, "USAHoliday", "Easter Sunday", "CANHoliday","Easter Sunday")
,ROW ("WeekNo", 16, "USAHoliday", "", "CANHoliday","Easter Monday")
,ROW ("WeekNo", 27, "USAHoliday", "Independence Day", "CANHoliday","")
,ROW ("WeekNo", 28, "USAHoliday", "", "CANHoliday","Independence Day")
,ROW ("WeekNo", 22, "USAHoliday", "Memorial Day", "CANHoliday","")
)
VAR AHoliday = DISTINCT(FILTER( UNION(SELECTCOLUMNS(A,
"WeekNo",[WeekNo]
,"Holiday",[USAHoliday]
),
SELECTCOLUMNS(A,
"WeekNo",[WeekNo]
,"Holiday",[CANHoliday]
)
),[Holiday]<>""))
VAR HolidayList=SUMMARIZE(AHoliday
,[WeekNo]
,"HolidayList.", CONCATENATEX(AHoliday,[Holiday],",", [Holiday],ASC)
)
EVALUATE HolidayList
Expected Result
HolidayList should be defined as, for example:
SUMMARIZE(
AHoliday,
[WeekNo],
"HolidayList",
CONCATENATEX(
FILTER( AHoliday, [WeekNo] = EARLIER( [WeekNo] ) ),
[Holiday],
", "
)
)

How to do if with multiple rows in PowerBi?

I have two tables like this
Table: creation date
ID user create date
1 ABC Jan 1, 2021
2 EFC Feb 1, 2021
3 HIJ Feb 1, 2021
1 ABC Feb 1, 2021
1 ABC Feb 20, 2021
And a log of blocking
ID user blocked from blocked till
1 ABC Jan 20, 2021 Feb 10, 2021
3 HIJ Jan 5, 2021 Jan 10, 2021
1 ABC Feb 25, 2021 Mar 10, 2021
As you can see the relationship between the tables are Many to Many. What I wanted to check is if the create date is during the blocked date in the log.
If it was ONE to MANY relationship, I could have used
Yes or No = IF(AND(creation date < RELATED(log[blocked from]), creation date > RELATED(log[blocked till])), "Yes", "No")
But now as there are multiple rows for the same ID how can I just check if the creation date is between any of the blocked from and Blocked till date?
You can use a measure like this
Measure2 =
VAR _maxID =
MAX ( creationDate[ID] )
VAR _minBlockedFrom =
CALCULATE (
MIN ( blockLog[blocked from] ),
FILTER ( VALUES ( blockLog[ID] ), blockLog[ID] = _maxID )
)
VAR _maxBlockedTill =
CALCULATE (
MAX ( blockLog[blocked till] ),
FILTER ( VALUES ( blockLog[ID] ), blockLog[ID] = _maxID )
)
VAR _maxDate =
MAX ( creationDate[create date] )
RETURN
IF ( _maxDate >= _minBlockedFrom && _maxDate <= _maxBlockedTill, "Yes", "No" )
Edit
please use a measure like this
Measure3 =
MAXX (
ADDCOLUMNS (
FILTER (
CROSSJOIN (
SELECTCOLUMNS (
creationDate,
"_id", creationDate[ID],
"_user", creationDate[user],
"_date", creationDate[create date]
),
blockLog
),
[_user] = [user]
),
"condition",
IF ( [_date] >= [blocked from] && [_date] <= [blocked till], "Yes", "No" )
),
[condition]
)
You can create a Measure as below-
is_from_block_range =
var current_row_id = min('CreationDate'[ID])
var current_row_user = min('CreationDate'[user])
var creation_date = min('CreationDate'[create date])
var chk_macth =
COUNTROWS(
FILTER(
all('BlockLog'),
'BlockLog'[ID] = current_row_id
&& 'BlockLog'[user] = current_row_user
&& 'BlockLog'[blocked from] <= creation_date
&& 'BlockLog'[blocked till] >= creation_date
)
)
return if(chk_macth >=1, "Yes", "No")
Output will be as below-

Slicer filtering on a list inside a table

assuming I have a table that has a list inside
+---------+--------------+
| tag | val |
+---------+--------------+
| [a,b,c] | 1 |
| [a,e] | 2 |
| [f,g] | 3 |
| [e,f] | 4 |
+---------+--------------+
can I create a slicer that when selected will still filter the item inside the list of the tag column?
eg. i select on the filter "a" it will show 1 and 2. "e" will filter 2 and 4, "f" will filter 3 etc.
You may create a measure (returning 1/0) where you use PATHCONTAINS function. We need to remove square bracket and replace commas to pipe "|"; This measure you can put to filter pane in table/matrix visualization https://dax.guide/pathcontains/
ForFilter =
var __selectedTag = SELECTEDVALUE(disconnected[tagList])
var __tags = SELECTEDVALUE('Table'[Tag])
var __path = SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(__tags,",","|"),"[",""),"]","")
return
IF(PATHCONTAINS(__path, __selectedTag),1,0)
EDIT:
version for multiple selection
var __string = CONCATENATEX( VALUES(disconnected[tagList]), disconnected[tagList],"|")
var __tags = SELECTEDVALUE('Table'[Tag])
var __path = SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(__tags,",","|"),"[",""),"]","")
VAR Table0 =
SELECTCOLUMNS(
TOPN(1,
SELECTCOLUMNS(
ADDCOLUMNS (
GENERATE (
ROW ( "tag", __path ,"Text",__string ),
VAR TokenCount =
PATHLENGTH ([Text] )
RETURN
GENERATESERIES ( 1, TokenCount )
),
"Word", PATHITEM ([Text], [Value] )
),
"Word",IF(PATHCONTAINS([tag],[Word]),1,0),
"Tag", [tag],
"Values", [Value]
), [Word],DESC, [Values])
,"Bool", [Word])
return
Table0

Power BI DAX - Need help in displaying Measure with Values and Text

I'm trying to display a measure value with text in Card Visual.  For instance, I'd like to display all IDs with HasWrongTitle = True by Department (Slicer).  Based on the below data, I'd like to show "2 of 4" without slicer selection and "1 of 4" with slicer set to IT or Finance.
The below measure works partially but displays the same value for total as well.
MeasureWrongTitle =
IF(
ISBLANK(
CALCULATE(
DISTINCTCOUNT(Table[ID]),
FILTER(
Table,
Table[HasWrongTitle]="True"
)
)
),
"0 of " &
COUNTROWS(
SUMMARIZE(
Table,
Table[ID]
)
),
CALCULATE(
DISTINCTCOUNT(Table[ID]),
FILTER(
Table,
Table[HasWrongTitle]="True"
)
) & " of " & COUNTROWS(SUMMARIZE(Table,Table[ID]
)
)
Table:
ID Name Department HasDirectReport HasWrongTitle
100 John Doe1 Admin True False
101 John Doe2 IT False True
102 John Doe3 HR True False
103 John Doe4 Finance True True
You can try this below measure with your logic but in simplified way-
MeasureWrongTitle =
var has_wrong_title_count =
CALCULATE(
DISTINCTCOUNT('Table'[ID]),
FILTER(
'Table',
'Table'[HasWrongTitle] = TRUE()
//-- User ""True" if your column is string type
)
)
var total_id = DISTINCTCOUNT('Table'[ID])
RETURN IF(has_wrong_title_count = BLANK(),0,has_wrong_title_count) & " of " & total_id
Here is the output using your data-