How do you define 1 to many relationship between two tables in Power BI, when multiple columns are involved.
I.E. Column A, B, and C in table 1 tied to Column E, F, and G in table 2, with a 1 to many relationship.
You can create a new column concatenating the fields like:
tied01 = CONCATENATE( CONCATENATE(your_dataset[Column A], your_dataset[Column B]), your_dataset[Column C])
And to
tied02 = CONCATENATE( CONCATENATE(your_dataset[Column E], your_dataset[Column F]), your_dataset[Column G])
Once you have these two new columns, you can merge them to only one column or create a dynamic table making the reference for the new created columns
Related
I've got a data warehouse which is underlying database of OLAP cube.
When I run query like that:
SELECT dimS.Attribute2,SUM(fact.LastValue)
FROM FactTable fact
JOIN DimS dimS ON fact.DimSKey = DimS.DimSKey
GROUP BY DimSKey.Attribute2
I can see that all existing Attribute2 at dimS table have corresponding rows at fact table.
On the other hand I've got a calculated measure:
CREATE MEMBER CURRENTCUBE.[MEASURES].[MyMeasure]
AS ([Measures].[FactTable - LastValue]
, [DimS].[S Hierarchy].[All].[Hierarchy SomeName]
, [DimS].[Category].[All]
, [DimS].[Question].CurrentMember
, [CimC].[Status].&[Active]
),DISPLAY_FOLDER='Folder',VISIBLE = 1;
and when running below MDX:
SELECT
{ [Measures].[MyMeasure] } ON COLUMNS,
{ ([Survey].[Attribute2].ALLMEMBERS ) } ON ROWS
FROM [MyCube]
I can see that 2 of Attribute2 have no values (null) assigned to them.
What can cause issue like that (DimS and cube has been just processed fully)?
Found the rootcause.
the reference in MDX definition of calculated measure to [DimS].[S Hierarchy].[All].[Hierarchy SomeName] is another calculated measure where actually we have hardcoded values within dimension hierarchy. And for [Attribute2] this condition is not met.
I am trying to count rows in a table based on multiple criteria in different columns of that table. The criteria are not directly in the formula though; they are arrays which I would like to refer to (and not list them in the formula directly).
Range table example:
Group Status
a 1
b 4
b 6
c 4
a 6
d 5
d 4
a 2
b 2
d 3
b 2
c 1
c 2
c 1
a 4
b 3
Criteria/arrays example:
group
a
b
status
1
2
3
I am able to do this if i only have one array search through a range (1 column) in that table:
{=SUM(COUNTIFS(data[Group],group[group]))}
Returns "9" as expected (=sum of rows in the group column of the data table which match any values in group[group])
But if I add a second different range and a different array I get an incorrect result:
{=SUM(COUNTIFS(data[Group],group[group], data[Status],status[status]))}
Returns "3" but should return "5" (=sum of rows which have 1, 2 or 3 in the status column and a or b in the group column)
I searched and googled for various ideas related to using sumproduct or defining arrays within the formula instead of classifying the whole formula as an array but I was not able to get expected results via those means.
Thank you for your help.
Because your group and status criteria are a different number of values (2 values for group, but 3 values for status), I'm not sure you can do this in a single formula. Best way I know of to do this would be to use a helper column (which can be hidden if preferred).
Put this array formula in a helper column and copy down the length of your data (array formulas must be confirmed with Ctrl+Shift+Enter):
=AND(OR(data[#Group]=group[group]),OR(data[#Status]=status[status]))
And then get the count with: =COUNTIF(helpercolumn,TRUE)
You could use a slightly different approach, using Power Query / Power Pivot.
Name your tables Data, Group and Status, then create the following query, named Filtered Data:
let
tbData = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
tbGroup = Excel.CurrentWorkbook(){[Name="Group"]}[Content],
tbStatus = Excel.CurrentWorkbook(){[Name="Status"]}[Content],
#"Merged Group" = Table.NestedJoin(tbData,{"Group"},tbGroup,{"Group"},"tbGroup",JoinKind.Inner),
#"Merged Status" = Table.NestedJoin(#"Merged Group",{"Status"},tbStatus,{"Status"},"Merged Status",JoinKind.Inner),
#"Removed Columns" = Table.RemoveColumns(#"Merged Status",{"tbGroup", "Merged Status"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Status", type number}})
in
#"Changed Type"
Load To as connection only, and tick Load to Data Model
Now create a DAX measure:
Status Sum:=SUM ( 'Filtered Data'[Status] )
You can then use the following formula on your worksheet, to get the Sum of Status values, for rows matching the criteria specified in the Group and Status tables:
=CUBEVALUE("ThisWorkbookDataModel","[Measures].[Status Sum]")
Simply refresh the data connection to update the value.
Database: Netezza (Let's say I have 10 rows in a source table)
I have source table where for e.g. Columns A, Column B, Column C, column D
has same values but different values in column E and column F in for example 6 rows.
And Also I have rows where values in Column A, Column B, column C, Column D, column E, Column
F are different.
Now I need a query which gives output for rows where above 4 columns
has same value should display in one line and two columns E and F with different values
Should display as single column concatenated (value of E, Value of F)
Select columnA, column B, column C, column D, column (E, F) from ;
And rows where values in Column A, Column B, column C, Column D, column E, column F are
Display in different rows as it is (since these records are unique).
I hope you guys understand my questions.
I need help to get output as mentioned above.
I have 3 tables: A,B,C.
A consists of a column D.
B consists of columns E,F,G,H,I,J (PK is J).
C consists of foreign key K to table B.
now I need to have F,G,H unique, but if G is null then have F,H unique and I and E unique. (and G XOR I must be null).
is there a way I can do it in db and not programatically?
Thanks.
I'm pretty sure you can do this with unique indexes and the fact that NULL is ignored for a unique index.
First, create an index on F, G, and H:
create unique index idx_b_f_g_h on b(f, g, h)
This handles the "F, G, H unique" case. To handle the "G is null, then F, H unique" do:
create unique index idx_b_f_h_j on b(f, h, (case when G is null then 0 else j end));
This replaces a non-NULL values of G with the primary key -- ensuring uniqueness. It uses an arbitrary "constant" value when G is null. (Note the constant should be of the same type as the primary key.)
To handle, I and E unique, you can also use a functional index. I think you mean:
create unique index idx_b_i_e_j on b(coalesce(i, e));
You can handle the fact that i or e is NULL using a check constraint.
I have several tables (let's call them A, B, C, D, etc.), where each has multiple columns (A has columns a1, a2, etc.).
I'd like to diagrammatically represent the following:
Inner join A and B where A.a1 = B.b1, then check the value of B.b2. If B.b2 = 1, inner join the result with C where A.a1 = C.c1. If B.b2 = 2, inner join the result with D where A.a1 = D.d1.
I've tried to use a traditional flowchart, but I'd like to keep track of the tables and their columns. With a database schema diagram, however, I'm not sure how to depict things like logical conditions.
What's the best way to do this?