Custom matrix header - powerbi

I need to create a custom header like the picture below:
I check this link Custom aggregate column in power bi matrix
But I don't undestand how to do the same to my case?
Edit
I try to create calculated table but I didn't get the data for dim5 and dim6, how can I modify it?
Edit
Dim_prduit
My problem is how to dispaly Nombre product , and then like hierarchy dim5 then dim6 in the header?

It's ugly but you can write a header table like this and then define a switching measure based on the appropriate indices:
Header =
ADDCOLUMNS (
UNION (
DATATABLE (
"Top", STRING,
"Index1", INTEGER,
"Middle", STRING,
"Index2", INTEGER,
"Bottom", STRING,
"Index3", INTEGER,
{
{ "Nombre product", 1, "", 0, "", 0 },
{ "Affaires nouvelles", 2, "Total", 8, "", 0 },
{ "Affaires nouvelles", 2, "%Total", 9, "", 0 }
}
),
SELECTCOLUMNS (
SUMMARIZECOLUMNS ( Dim_Prod[dim5], Dim_Prod[dim6] ),
"Top", "Affaires nouvelles",
"Index1", 2,
"Middle", Dim_Prod[dim5],
"Index2", RANK.EQ ( Dim_Prod[dim5], Dim_Prod[dim5], ASC ),
"Bottom", Dim_Prod[dim6],
"Index3", RANK.EQ ( Dim_Prod[dim6], Dim_Prod[dim6] )
)
),
"Index0", 100 * [Index1] + 10 * [Index2] + [Index3]
)
Output:
Sample measure:
SampleMeasure =
VAR Top = SELECTEDVALUE ( Header[Top] )
VAR Middle = SELECTEDVALUE ( Header[Middle] )
VAR BottomIndex = SELECTEDVALUE ( Header[Index3] )
RETURN
SWITCH (
TRUE (),
Top = "Nombre product", [NombreProductMeasure],
Top = "Affaires nouvelles" && BottomIndex <> 0, [DimensionMeasure],
Middle = "Total", [TotalMeasure],
Middle = "%Total", [%TotalMeasure]
)
This is pretty hacky though. Power BI may not be the best tool here.

Power BI is not a pixel-perfect data visualization tool, therefore, it is not possible to create customer headers using Built-in visualizations.
Therefore you have pretty much two options:
Build your own custom visualization, using Javascript, Python or R
Use a pixel-perfect tool like SSRS

Related

I want to setup a RLS using this table in Power BI Embedded where I am only fetching Scheme Code as userprincipalname()

I am looking to setup RLS in Power BI Embedded using below table where SCHEMECODE should be my userprincipalname() and through the webapp user can have multiple SCHEMECODE's which will be comma separated. This is an example of what I will be getting from the webapp "16856,39760"
What you may try is to split your string into table of separate values;
Then in RLS 'YourTable'[SCHEMACODE] in TableOf (code below);
EVALUATE
VAR _userprincipalname = "16856,39760"
VAR SplitByCharacter = ","
VAR Table0 =
SELECTCOLUMNS(
ADDCOLUMNS (
GENERATE (
ROW ( "Text", _userprincipalname ),
VAR TokenCount =
PATHLENGTH ( SUBSTITUTE ( [Text], SplitByCharacter, "|" ) )
RETURN
GENERATESERIES ( 1, TokenCount )
),
"Word", PATHITEM ( SUBSTITUTE ( [Text], SplitByCharacter, "|" ), [Value] )
),
"Word",[Word])
RETURN
Table0

How to get the Top N vales based on a column for each category in PowerBI?

I am facing the issue while filtering out the data based on a "Date" column to fetch top 3 for each category. Below is the sample data:
Can anybody help me with this to get the below-expected output?
You can try this (here dummy data); You can choice ASC or DESC based on your need:
Ranking by Date = var _cat = SELECTEDVALUE( Sheet1[Category])
return
IF(RANKX(FILTER(ALL(Sheet1), Sheet1[Category]= _cat), calculate(MAX(Sheet1[Date])),,ASC ,Skip)<=2, 1,BLANK())
or by Sale:
Ranking by Sales =
IF (
ISINSCOPE ('Sheet1'[Date] ),
VAR ProductsToRank = 2
VAR SalesAmount = [SumOf]
RETURN
IF (
SalesAmount > 0,
VAR VisibleProducts =
CALCULATETABLE (
VALUES ( 'Sheet1' ),
ALLSELECTED ( 'Sheet1'[Date] )
)
VAR Ranking =
RANKX (
VisibleProducts,
[SumOf],
SalesAmount
)
RETURN
IF (
Ranking > 0 && Ranking <= ProductsToRank,
1
)
)
)
Or you can create a new table in DAX like this:
Top2 = GENERATE(VALUES(Sheet1[Category]), TOPN(2, FILTER(SELECTCOLUMNS(ALL(Sheet1[Category], Sheet1[Date]),"Cat",[Category],"Date",[Date]),[Cat] = [Category]),[Date]))

Power BI Dax - Trying to break circular dependency after one attempt

I am trying to figure out ancestor bloodline in data I have. I feel like there is something I am missing to make this work. This data wouldn't change so not sure if I am missing something I can write in the power query editor when loading / refreshing the data.
While technically it is circular in fields it never going to return the same row it is currently in and the first generation is hard number making a starting point. I only want to reference the mother and father to calculate the child's bloodline. The first generation is a basic IF() statement. Below is as far as I can get before hitting the circular dependency error. I have tried a few things to break it thinking its going to loop.
Logic is:
Each blood is 100% for 1st generations based on their birthplace then it is ((mother blood + father blood) / 2) for each generation after that. I found I can use PATHITEM() to isolate the type of blood but errors with a circular dependency. (This is where I can't figure out how to reference the mother / father to do the calculation.) If I take this part out I get the image below working for 1st generation and correct mother / father for second generation.
Asisa Blood =
VAR current_id = 'Sheet1'[ID]
VAR current_gen = 'Sheet1'[Generation]
VAR current_blood = 'Sheet1'[Birthplace]
VAR current_mother_blood =
PATHITEM(
CALCULATE(
DISTINCT('Sheet1'[Mother's Blood Mix]),
FILTER(
ALLNOBLANKROW('Sheet1'[ID]),
'Sheet1'[ID] = current_id
),
REMOVEFILTERS('Sheet1')
),1,INTEGER)
VAR current_father_blood =
PATHITEM(
CALCULATE(
DISTINCT('Sheet1'[Father's Blood Mix]),
FILTER(
ALLNOBLANKROW('Sheet1'[ID]),
'Sheet1'[ID] = current_id
),
REMOVEFILTERS('Sheet1')
),1,INTEGER)
VAR gen1_value = 100
RETURN
IF(AND(LOWER(current_gen) = "1",LOWER(current_blood) = "asisa"),
gen1_value,
((current_mother_blood + current_father_blood)/2)
)
Blood Mix concatenates the four blood types into one field for easy look up in next step.
Blood mix =
VAR current__id = 'Sheet1'[ID]
VAR current_blood_a = 'Sheet1'[Asisa Blood]
VAR current_blood_b = 'Sheet1'[Africa Blood]
VAR current_blood_c = 'Sheet1'[Europe Blood]
VAR current_blood_d = 'Sheet1'[North America Blood]
RETURN
current_blood_a & "|" & current_blood_b & "|" & current_blood_c & "|" & current_blood_d
Mother and Father are lookups on blood mix with mother or father ids
Mother's Blood Mix =
VAR current_id = 'Sheet1'[ID]
VAR current_gen = 'Sheet1'[Generation]
VAR gen_value = 'Sheet1'[Blood mix]
VAR current_parent_id =
IF(LOWER(current_gen) = "1",current_id,'Sheet1'[Mother ID])
VAR result =
CALCULATE(
DISTINCT('Sheet1'[Blood mix]),
FILTER(
ALLNOBLANKROW('Sheet1'[ID]),
'Sheet1'[ID] = current_parent_id
),
REMOVEFILTERS('Sheet1')
)
RETURN
result
You can try to do this way (rather high resource consuming):
NEW COLUMN:
heritage_Father = PATH(Blood[ID],(Blood[FatherID]))
heritage_Mother = PATH(Blood[ID],(Blood[MotherID]))
Mancestor = LOOKUPVALUE(Blood[heritage_Mother],Blood[ID],Blood[FatherID]) &"|"& Blood[heritage_Mother]
Fancestor = LOOKUPVALUE(Blood[heritage_Father],Blood[ID],Blood[MotherID])&"|"&Blood[heritage_Father]
NEW MEASURE:
ASIA_check =
VAR Table0 =
SELECTCOLUMNS(
ADDCOLUMNS (
GENERATE (
ROW ( "Text", "0"&SELECTEDVALUE(Blood[Fancestor]) ),
VAR TokenCount =
PATHLENGTH ( [Text] )+1
RETURN
GENERATESERIES ( 1, TokenCount )
),
"Word", PATHITEM ( [Text], [Value] )
),
"Word",VALUE([Word]))
VAR Table1 =
SELECTCOLUMNS(
ADDCOLUMNS (
GENERATE (
ROW ( "Text", "0"&SELECTEDVALUE(Blood[Mancestor]) ),
VAR TokenCount =
PATHLENGTH ( [Text] )+1
RETURN
GENERATESERIES ( 1, TokenCount )
),
"Word", PATHITEM ( [Text], [Value] )
),
"Word",VALUE([Word]))
RETURN
DIVIDe(
if(SELECTEDVALUE(Blood[Generation]) <> 1,
calculate(sum(Blood[AsiaBlood]), FILTER(ALL(Blood), Blood[ID] in Table0 || Blood[ID] in Table1)),0
),
(POWER(2, SELECTEDVALUE(Blood[Generation])-1)))
AFRICA_check =
VAR Table0 =
SELECTCOLUMNS(
ADDCOLUMNS (
GENERATE (
ROW ( "Text", "0"&SELECTEDVALUE(Blood[Fancestor]) ),
VAR TokenCount =
PATHLENGTH ( [Text] )+1
RETURN
GENERATESERIES ( 1, TokenCount )
),
"Word", PATHITEM ( [Text], [Value] )
),
"Word",VALUE([Word]))
VAR Table1 =
SELECTCOLUMNS(
ADDCOLUMNS (
GENERATE (
ROW ( "Text", "0"&SELECTEDVALUE(Blood[Mancestor]) ),
VAR TokenCount =
PATHLENGTH ( [Text] )+1
RETURN
GENERATESERIES ( 1, TokenCount )
),
"Word", PATHITEM ( [Text], [Value] )
),
"Word",VALUE([Word]))
RETURN
DIVIDe(
if(SELECTEDVALUE(Blood[Generation]) <> 1,
calculate(sum(Blood[AfricaBlood]), FILTER(ALL(Blood), Blood[ID] in Table0 || Blood[ID] in Table1)),0
),
(POWER(2, SELECTEDVALUE(Blood[Generation])-1)))

Compare similar values within a table in power BI

I have fields within a table with values originally filled in by hand. Even if the same values are entered/meant, there can be "slight" deviations. Now I want to compare whether values in 2 columns within a row are quite similar.
If there is some similarity, I would like to have a True in a new column, otherwise a False. The use case is similar to the fuzzy join when two tables are merged, but the fields are within a table and do not work as a primary key. I have created a table below of what this should look like:
No
​A header
Another header
Calculated Column
1
Zürich, 1.OG Telefonzentrale
Telefonzentrale
True
2
Mittelterrasse 1.OG Raum T190
Mittelterrasse T1
True
1
TM-Raum 225
Bern, Bollwerk 10 / 2.OG
False
2
G7803
91G7803
True
It would be great if someone could help me in this topic.
I dont know if is there a way to do this, but we can try to verify how many word from column1 appear in column2:
CheckIfTrue__ =
VAR SplitByCharacter = " "
VAR Org = SELECTEDVALUE(Sheet3[​A header])
VAR CurrentF = SELECTEDVALUE(Sheet3[Another header] )
VAR Table0 =
SELECTCOLUMNS(
ADDCOLUMNS (
GENERATE (
ROW ( "Text", Org),
VAR TokenCount =
PATHLENGTH ( SUBSTITUTE ( [Text], SplitByCharacter, "|" ) )
RETURN
GENERATESERIES ( 1, MAX(TokenCount,1) )
),
"Word", PATHITEM ( SUBSTITUTE ( [Text], SplitByCharacter, "|" ), [Value] )
),
"Word",[Word])
VAR Table1 =
SELECTCOLUMNS(
ADDCOLUMNS (
GENERATE (
ROW ( "Text", CurrentF),
VAR TokenCount =
PATHLENGTH ( SUBSTITUTE ( [Text], SplitByCharacter, "|" ) )
RETURN
GENERATESERIES ( 1, MAX(TokenCount,1) )
),
"Word", PATHITEM ( SUBSTITUTE ( [Text], SplitByCharacter, "|" ), [Value] )
),
"Word",[Word])
RETURN
COUNTROWS(INTERSECT(Table0, Table1))+0

Power BI, DAX, Many-to-one and relational tables

I previously asked a question here:
DAX subquery measure?
for instruction on how to create a specific measure column for a visualisation. To keep the example simple, I kept it to one fictitious table and the DAX query worked really well.
In reality, however, the visualisation that the measure column is for is made up of multiple joined tables. And the results of the DAX query unexpectedly produced all zeros! So I'll refactor my example here for more help...
Requirement
I want a count of how many 'Apps' are not equal to 'Complete' for a specific 'Build'.
Data Model
Builds
Build
App
Apps
App
Status
Sample Data
Builds
Build...........App
Build1..........App1
Build1..........App2
Build1..........App9
Build2..........App3
Build3..........App1
Build3..........App5
Build3..........App8
Build3..........App9
Apps
App...........Status
App1..........UAT
App2..........Complete
App9..........New
App3..........Complete
App5..........UAT
App8..........Complete
Relationship
The relationship is MANY Builds.App to ONE Apps.App.
Visualisation Table
This is my visualisation - note the different tables:
Builds.Build....Builds.App....Apps.Status
Build1..........App1..........UAT
Build1..........App2..........Complete
Build1..........App9..........New
Build2..........App3..........Complete
Build3..........App1..........UAT
Build3..........App5..........UAT
Build3..........App8..........Complete
Build3..........App9..........New
This is my required results:
Builds.Build....Builds.App....Apps.Status....AppsNotCompleteForBuild
Build1..........App1..........UAT............2
Build1..........App2..........Complete.......2
Build1..........App9..........New............2
Build2..........App3..........Complete.......0
Build3..........App1..........UAT............3
Build3..........App5..........UAT............3
Build3..........App8..........Complete.......3
Build3..........App9..........New............3
ATTEMPT 1 (Not working!)
CALCULATE (
COUNT ( Builds[App] ),
FILTER (
ALL ( Builds[Build], Builds[App] ),
Builds[Build] = SELECTEDVALUE ( Builds[Build] )
),
FILTER (
ALL ( Apps[Status] ),
Apps[Status] <> "Complete"
)
) + 0
ATTEMPT 2 (Not working!)
Measure 5 = CALCULATE (
COUNT ( Builds[App] ),
FILTER (
ALL ( Builds[Build] ),
Builds[Build] = SELECTEDVALUE ( Builds[Build] )
),
FILTER (RELATEDTABLE(Apps),
Apps[Status] <> "Complete")
) + 0
ATTEMPT 3 (Not working!)
Measure5 = CALCULATE (
COUNTAX(FILTER( Builds
, RELATED(Apps[Status]) <>"Complete"
&& Builds[Build] = SELECTEDVALUE(Builds[Build])
)
,Builds[App])
) + 0
using these tables with a many to one relationship between Builds and Apps
Builds =
DATATABLE(
"Build", STRING,
"App", STRING,
{
{ "Build1", "App1" },
{ "Build1", "App2" },
{ "Build1", "App9" },
{ "Build2", "App3" },
{ "Build3", "App1" },
{ "Build3", "App5" },
{ "Build3", "App8" },
{ "Build3", "App9" }
}
)
Apps =
DATATABLE(
"App", STRING,
"Status", STRING,
{
{ "App1", "UAT" },
{ "App2", "Complete" },
{ "App9", "New" },
{ "App3", "Complete" },
{ "App5", "UAT" },
{ "App8", "Complete" }
}
)
we can write a dax measure that counts the number of apps per build that are not in "Complete" status. Since an app can have just one status, otherwise the many to one relationship would break, it's enough to filter out status = "Complete" when counting.
# not complete =
IF(
HASONEVALUE( Builds[Build] ),
VAR CurrentBuild =
SELECTEDVALUE( Builds[Build] )
RETURN
COUNTROWS(
FILTER(
ALL( Builds ),
Builds[Build] = CurrentBuild
&& RELATED( Apps[Status] ) <> "Complete"
)
) + 0
)
With this formula we can use a Table Visual to get this result
Edit: this will also handle cases where there are missing Apps in Apps table, just ignoring them
# not complete =
IF(
HASONEVALUE( Builds[Build] ),
VAR CurrentBuild =
SELECTEDVALUE( Builds[Build] )
VAR CurrentApp =
SELECTEDVALUE( Apps[App] )
VAR Result =
COUNTROWS(
FILTER(
ALLNOBLANKROW( Builds ),
Builds[Build] = CurrentBuild
&& RELATED( Apps[Status] ) <> "Complete"
&& NOT ISBLANK( RELATED( Apps[Status] ) )
)
) + 0
RETURN
IF( NOT ISBLANK( SELECTEDVALUE( Apps[Status] ) ), Result )
)