Display Related Value in Table Visual With a Hierarchy - powerbi

Data
Main
Group
Subgroup
Value
Composite Key
A
1
1
A - 1
A
2
2
A - 2
B
1
3
B - 1
C
1
4
C - 1
C
1
5
C - 1
C
2
6
C - 2
C
2
7
C - 2
Targets
Group
Subgroup
Target
Composite Key
A
1
10
A - 1
A
2
11
A - 2
B
1
12
B - 1
C
1
13
C - 1
C
2
14
C - 2
Setup
I have 2 datasets like the ones given above. Table main stores, well, my main data and table targets defines tragets for each combination of Group and Subgroup. I want to bring this 2 tables in a relation. Thus, I created columns in each table which paste the 2 key columns (Group and Subgroup together (Composite Key) and defined an 1:n relationship between these 2 tables.
Furthermore, I defined a hierarchy on Group > Subgroup on the main table (lets call it group hierarchy).
Goal
I want to show a matrix visual which uses group hierarchy in the rows (effectively allowing to fold / unfold the groups), some measure as values. So far so good. Now I want to add the target from table targets to the visual and here is where I am struggling, because if I simply add Targets[Target] to the visual it only shows the overall average of the targets and not the average of the specific group. Hence, I guess I need to define a meausre myself which does some RELATEDTABLE magic to pull the correct target, but I am totally at loss of how to do that. Any ideas?

It turned out that I need to define the hierarchy on Targets as well and use this hierarchy in the visual:
Then the numbers were calculated properly:

Related

Informatica : Count the number of rows based on sequence of number

I have table where source has 1 column, like below. for example, column name is A and I have set of records in the source.
A
1
1
1
2
2
3
I want to populate two columns in target, Say columns are A and B.
Column A in the Target has same values as in source and column B has count
A B
1 1
1 2
1 3
2 1
2 2
3 1
Can someone please explain how can i achieve this.
Thanks in advance
If source is a dbms like oracle, you can use source qualifier overwrite sql like below. Use row number and partition by to generate sequence for every A.
Select
A, row_number() over(partition by A order by A) as B
From mytable
If you're looking for infomatica only solution then this is how you can do it.
Sort the data by column A
Use ex transformation, create one in/out two var, and one out port.
We are going to compare first val with prev val, if they r same, add 1to the sequence else start from 1 again.
A in/out
v_B = iif (A=prev_A, v_B +1, 1)
prev_A=A
o_B =v_B
Link A and o_B to the target.

data model in Power BI with multiple tables each has an FK

Assume I have the following tables:
Table 1:
Prj_id, name
1 , prj1
2 , prj2
3 , prj3
Table 2
prj_id, cost, year
1 ,100 ,1999
1 ,200 ,2000
1 ,300 ,3000
2 ,150 ,1998
Table 3
Prj_id, manager
1 , xxx
1 , yyy
2 , xxx
3 , zzz
Now my question is:
Shall I connect all tables together in the model (relation tab) of BI, if I have all the attributes as filters on the page
i.e.
Table 1 to 2 ->Both direction
Table 1 to 3 ->Both direction
Table 2 to 3 ->Both direction
or shall I need to only join tables as follows:
Table 1 to 2->Both direction
Table 1 to 3->Both direction
That highly depends on what your final goal is.
However I would create a relationship between this tables. As I looks, these data coming from a database with a good structure, so why joining every together again.

If all values in list are not present, create rows with missing values

This needs a little bit of information.
I have a list of user IDs. I also have 20 modules that an user can be associated with, each module with a number of sessions that can be counted.
I currently have a table like this:
UserID Module Count
A 1 3
A 2 3
B 1 2
B 3 2
C 1 3
C 2 3
C 3 3
What am I trying to achieve is the following:
For every user ID, I need to check if there is one row per module, considering all 20 modules. The way the table is set up right now, when an user has nothing on a module, I don't have a row for the module they are not involved with. If there's a row missing, it should create the row for the missing module and set Count to 0.
So assuming the table above only considers 3 modules, I would need to transform it into:
UserID Module Count
A 1 3
A 2 3
A 3 0
B 1 2
B 2 0
B 3 2
C 1 3
C 2 3
C 3 3
How would I got about doing that?
I'm getting my first row by grouping another table per module, where the count is the number of rows on the other table. However this doesn't deal with the missing modules, and I still need to report them as 0.
You could try:
NewTable =
VAR T1 = SUMMARIZECOLUMNS ( Table1[UserID] )
VAR T2 = SUMMARIZECOLUMNS ( Table1[Module] )
RETURN
ADDCOLUMNS (
CROSSJOIN ( T1, T2 ),
"Count",
LOOKUPVALUE (
Table1[Count],
Table1[UserID], [UserID],
Table1[Module], [Module]
) + 0
)
See https://pwrbi.com/so_55398321/ for a worked example PBIX file

Understanding the DAX CALCULATE function

I am working on a model in Power BI that has two datasets:
Set_1 (just a list of each group name)
Group:
1
2
3
and Set_2, a bunch of values per group in a different dataset:
Group: Value:
1 10
1 20
1 -7
2 100
2 -25
3 45
3 15
1 3
The tables are related by group. I want to create a measure on Set_1 that shows the sum of the values by group in Set_2. I can do so with the following DAX formula:
GroupSum = CALCULATE(SUMX(Set_2, Set_2[Value]))
looks like this
Group: GroupSum:
1 26
2 75
3 60
But I don't understand why the CALCULATE function, which doesn't take any filter contexts as parameters works the way it does in this instance. Without the CALCULATE function,
GroupSum = SUMX(Set_2, Set_2[Value])
looks like this:
Group: GroupSum:
1 161
2 161
3 161
Which makes sense. I just need help understanding how the Calculate function works, specifically when it isn't passed any filter parameters.
EDIT: The answer lies in the concept of "context transition" as pointed out below.
Using the CALCULATE function makes the DAX perform a context transition.
CALCULATE transforms all existing row contexts into an equivalent filter context before applying its filter arguments to the original filter context.
For more detail on this, check out the site I quoted above:
Understanding Context Transition.
In your example, the value in the Group column of each row acts as a filter when you use CALCULATE as if you had written something like CALCULATE(SUM(Set_2[Value]), Set_2[Group] = 1). Even though it doesn't have an explicit filter, the row context acts as a filter.

Generating a List in M Query

I am trying to generate a list using M Query, but instead of generating a list starting from a specific, number, I want the number to start at 1 and then add 1 for every row on another table.
So for example, if I have:
Tbl1
Col1
A
B
C
D
D
I want to generate
Tbl2
Col1
1
2
3
4
5
I want the number to start at 1 and then add 1 for every row on another table.
if I understand your correctly, here it is:
={1..Table.RowCount(Tab1)}