Informatica Powercenter One to Many SQ Query and Mapping Issues - informatica

I have multiple VIEWs where the PERSON_VIEW to a PHONE_VIEW has a one to many relationship. In the following query, I got TOAD to correctly output the result into 1 row for each person record.
I am having a problem getting it to work with Informatica Powercenter. I copied/pasted the query to SQ SQL Query section.
Since the query takes the PHONE_NUMBER and check against the PHONE_TYPE on whether it is of type HOME, BUSINESS, or PERSONAL, it output 3 phone number columns called HOME, BUSINESS, and PERSONAL.
I created 3 new columns in the SQ Ports called HOME, BUSINESS, and PERSONAL to match the query output columns. When I validate the query, it constantly says it must match 28 ports from the SQ. When I just add 1 column and map to Exp Transformation and then to the Target, it still give this error. I counted the ports and it is 29. If I removed the phone columns, it works and the count is 28. When I add just one phone column, it gives the error.
I think I am missing a step.
Any help is appreciated.
PERSON VIEW
1 John M. Doe
PHONE VIEW
1 111-111-1111 HOME
1 222-222-2222 BUSINESS
1 333-333-3333 WORK
TOAD Result
1 John M. Doe 111-111-1111 222-222-2222 333-333-3333
Here is the QUERY (This works in TOAD)
SELECT PERSON.PERSON_ID,
PERSON.FIRST_NAME,
PERSON.MIDDLE_NAME,
PERSON.LAST_NAME,
PHONE.HOME,
PHONE.BUSINESS,
PHONE.PERSONAL,
PHONE_TYPE
FROM PERSON_VIEW PERSON
LEFT JOIN (SELECT * FROM (SELECT PERSON_ID, PHONE_TYPE,PHONE_NUMBER
FROM PHONE_VIEW)
PIVOT
(
MAX(PHONE_NUMBER)
FOR PHONE_TYPE in ('HOME' AS HOME,'PERSONAL' AS PERSONAL , 'BUSINESS' AS BUSINESS)
)
)PHONE ON PHONE.PERSON_ID = PERSON.PERSON_ID

Related

Power BI How to remove duplicate rows?

In my report view, I have a table where the rows are repeated twice => once for each position available. I want to show only one row for each employee with his latest position. How can I accomplish this?
Name
Project
Date
Position
John Smith
PowerProject
01-01-2021
Engineer
John Smith
PowerProject
01-01-2021
Senior Engineer
Sort on the date. Group on the name. Choose All Rows as the function and change the code from _ to Table.Last(_) then expand

Power BI - Filtering model on latest version of all attributes of all dimensions through DAX

I have a model that's comprised of multiple tables containing, for every ID, multiple rows with a valid_from and valid_to dates.
This model has one table in that is linked to every other table (a table working as both a fact and a dimension).
This fact has bi-directional cross filtering with the other tables.
I also have a date dimension that is not linked to any other table.
I want to be able to calculate the sum of a column in this table in the following way:
If a date range is selected, I want to get the sum of the latest value per ID from the fact able that is before the max selected date from the date dimension.
If no date is selected, I want to get the sum of the current version of the value per ID.
This comes down to selecting the latest value per ID filtered on the dates.
Because of the nature of the model (bi-directional with the fact/dimension table), I want to have the latest version of any attribute from any dimension selected in the visual.
Here's an data example and the desired outcome:
fact/dimension table:
ID
Valid_from
Valid_to
Amount
SK_DIM1
SK_DIM2
1
01-01-2020
05-12-2021
50
1234
6787
1
05-13-2021
07-31-2021
100
1235
6787
1
08-01-2021
12-25-2021
100
1236
6787
1
12-26-2021
12-31-2021
200
1236
6787
1
01-01-2022
12-31-9999
200
1236
6788
Dimension 1:
ID
SK
Valid_from
Valid_to
Name
1
1234
10-20-2019
06-01-2021
Name 1
1
1235
06-02-2021
07-31-2021
Name 2
1
1236
08-01-2021
12-31-9999
Name 3
Dimension 2:
ID
SK
Valid_from
Valid_to
Name
1
6787
10-20-2019
12-31-2021
Name 1
1
6788
01-01-2022
12-31-9999
Name 2
My measure is supposed to do the following:
If no date is selected than the result will be a matrix like the following:
Dim 1 Name
Dim 2 Name
Amount Measure
Name 3
Name 2
200
If July 2021 is selected than the result will be a matrix like the following:
Dim 1 Name
Dim 2 Name
Amount Measure
Name 2
Name 1
100
So the idea here is that the measure would filter the fact table on the latest valid value in the selected date range, and then the bi-directional relationships will filter the dimensions to get the corresponding version to that row with the max validity (last valid row) in the selected range date.
I have tried to do the following two DAX codes but it's not working:
Solution 1: With this solution, filtering on other dimensions work and I get the last version in the selected date range for all attributes of all used dimensions. But the problem here is that the max valid from is not calculated per ID, so I only get the max valid from overall.
Amount Measure=
VAR _maxSelectedDate = MAX(Dates[Dates])
VAR _minSelectedDate = MIN(Dates[Dates])
VAR _maxValidFrom =
CALCULATE(
MAX(fact[valid_from]),
DATESBETWEEN(fact[valid_from], _minSelectedDate, _maxSelectedDate)
|| DATESBETWEEN(fact[valid_to], _minSelectedDate, _maxSelectedDate)
)
RETURN
CALCULATE(
SUM(fact[Amount]),
fact[valid_from] = _maxValidFrom
)
Solution 2: With this solution, I do get the right max valid from per ID and the resulting number is correct, but for some reason, when I use other attributes from the dimensions, it duplicates the amount for every version of that attribute. The bi-directional filtering does not work anymore with Solution 2.
Amount Measure=
VAR _maxSelectedDate = MAX(Dates[Dates])
VAR _minSelectedDate = MIN(Dates[Dates])
VAR _maxValidFromPerID =
SUMMARIZE(
FILTER(
fact,
DATESBETWEEN(fact[valid_from], _minSelectedDate, _maxSelectedDate)
|| DATESBETWEEN(fact[valid_to], _minSelectedDate, _maxSelectedDate)
),
fact[ID],
"maxValidFrom",
MAX(fact[valid_from])
)
RETURN
CALCULATE(
SUM(fact[Amount]),
TREATAS(
_maxValidFromPerID,
fact[ID],
fact[valid_from]
)
)
So if somebody can explain why the bi-directional filtering doesn't work anymore that will be great, and also, more importantly, if you have any solution to have both the latest value per ID and still keep filtering on other attributes, that would be great!
Sorry for the long post, but I thought it's best to give all the details for a complete understanding of my issue, this has been picking my brain since few days now and I'm sure I'm missing something stupid but I turned to this community for help because I cannot seem to be able to find a solution!
Thank you very much in advance for any help!
Seems to be workable with a dummy model. I didn't got the point how filter ID, so if it creates a problem let me know how you handle ID. Then I changed fact to facts as fact is a function. Also, I'm not sure about the workability of the measure at your real model. Hope you will give some feedback.
Amount Measure =
VAR ValidDate=
calculate(
max(facts[Valid_to])
,ALLEXCEPT(facts,facts[ID])
,facts[Valid_to]<=MAX(Dates[Date])
)
Return
CALCULATE(
SUM(facts[Amount])
,TREATAS({ValidDate},facts[Valid_to])
)

Unable to get desired results when trying to slice for multiple accounts

In my sales report, I have run into a problem where sales for some customers are sold under another customer and I need to attribute sales to both to show truly accurate values.
Pictured below are the tables in question. tblTicketDetails is my facts table with the other two being my dimension tables.
Here is an example of the accounts in question:
In the above example, all values in [Account #] belong to customer 1 and values in [LookupAccount] belong to others (lets say customer 2 and 3).
I typically use [Customer Name] as my value in my Slicer as all accounts for a customer are named the same.
The outcome I have been trying to obtain is when I slice by customer 1, I get all values shown in [Account #] that have Customer 1 as the name but if I slice by customer 2 (who lets say has one account and is 5809), I will get all [Account #] that equal 5809 as well as all [Account #] whos [LookupAccount] is also 5809 (so I would also get 23634, 37765, 67804 and 95511).
The same applies to those who have multiple accounts, so if I slice by customer 3 whos accounts are lets say 14650, 89670 and 47900, I would get those results from [Account #] as well as the accounts where {LookupAccount] matches, which in this case would be 19734, 28199 and 64218.
I have tried changing the relationship between tblCustomers and tblTicketDetails, I have also added in the table LookupAccount as an in-between for the many to many relationship but none of those have actually changed the results I get (or they cause the visuals to go blank).
What am I missing?
Based on clarification from the author, here is my updated answer.
There are three objects in this model:
Sales in tblTicketDetails
Customers in tblCustomers
A matching table between the two, currently LookupAccount (the table)
Here is a abstract of the set or rules at stakes :
A sale has an account number
A customer is identified by his account number, let's call it primary account
A customer might use another account number in some situation. Let's call it secondary account
The goal is: when filtering on a customer, all sales are return whether they are through his primary account or secondary account.
The maching table LookupaAccount needs a rework for the model to function properly. For the stake of clarification, columns are renamed:
Account# → Primary
LookupAccount → Secondary
Here is an example:
Primary
Secondary
1
2
1
3
2
4
In that example:
Client account 1 has sales on accounts: 1, or 2, or 3.
Client account 2 has sales on accounts: 2, or 4.
In PowerQuery, we want to do some transformations:
Duplicate Primary column and call it CustomerAccount. This is the foreing key that will links to tblCustomers.
Unpivot columns Primary and Secondary with the value column renamed as ReportingAccount, which will be the foreign key to tblTicketDetails
The end result should look like this:
CustomerAccount
Attribute
ReportingAccount
1
Primary
1
1
Secondary
2
1
Primary
1
1
Secondary
3
2
Primary
2
2
Secondary
4
Then, you modify the relationships in your model:
tblTicketDetails is connected to LookupAccount (table) from field Account# to ReportingAccount
LookupAccount (table) is connected to tblCustomers from field CustomerAccount to Account#
Normaly this model should flow better.
Now, you can create measure to calculate de amount of sales per customer :
SalesperCustomer =
CALCULATE(
SUM(tblTicketDetails[Total])
)
Or, for example just the sales through primary account
SalesperCustomer_primary =
CALCULATE(
SUM(tblTicketDetails[Total])
LookupAccount[Attribute] = 'Primary'
)

Power BI translating a sql query to filters

I was wondering if this is possible in Power BI, I am extremely new to this and I am trying to relate how a sql query can translate in to a power bi report.
SELECT
expiresDate,
Name,
Addr,
ValidFrom,
ValidTo,
ChildName,
ChildValidFrom,
ChildValidTo,
RecValidFrom,
RecValidTo
FROM Table
WHERE expiresDate Between <date1> and <date2>
AND <Date3> BETWEEN ValidFrom AND ValidTo
AND <Date3> BETWEEN ValidFrom AND ValidTo
AND <Date3> BETWEEN ValidFrom AND ValidTo
A brief explanation. The report is for 3 months in advance. So in August the report is for September <date1 = 01/09/2021) and October (date2 = 31/10/2021) data. However the data can change on a daily basis. So this depends on Date3 which could be any day in August.
I have created a table that is a calendar and has the additional columns that calculate the start and end dates from a particular date. I just can't work out how to relate this to the dataset which is the query without the WHERE. I would then want the filters to be able to determine the result. Ultimately as I have it at present a single date that will then get the dates from the start and end dates as described earlier. Or display by range using the latest iteration of the record to display.
For example, First part of table
expiresDate
AccNo
Name
Addr
ValidFrom
ValidTo
ChildName
2021-10-01
1
Robert
1 Here
2019-01-01
2021-08-16
Cheese
2021-10-01
1
Robert
1 Here
2019-01-01
2021-08-16
Rhubarb
2021-10-01
1
Bob
1 Here
2021-08-17
2020-08-23
Rhubarb
Second half of table
ChildValidFrom
ChildValidTo
RecValidFrom
RecValidTo
2019-01-01
2021-08-10
2019-19-01
2020-12-31
2021-08-11
2021-08-23
2021-01-01
2021-08-15
2021-08-11
2021-08-23
2021-08-16
2020-08-23
The table is a view which has squashed the data to unique records and when the changes occurred. The dataset is considerably lower, a record count from 10m to 54k.
The requirement is that all To - From dates are within the date specified. Either being a date in the calendar that is entered as a filter... or today.
The report would bring out all records that have an expiryDate greater than 1 calendar month of the date, and less than 3 calendar months. I am just using August dates for the example so this would be from the 01/09/2021 - 31/10/2021.
If I use date 2021-08-01.
In my example there are 3 results for AccNo 1, but Only 1 should be displayed.
If I use the date 2021-08-01 the first row would be displayed.
If I use the date 2021-08-12 the second row should displayed.
If I use the date 2021-08-23 the third row should displayed.
Because the date used should fall between the date range of all 3 criteria
ValidFrom - ChildValidTo
ChildValidFrom - ChildValidTo
RecValidFrom - RecValidTo
Any help would be greatly appreciated. This is extremely frustrating, but I can understand that if this is possibly that this would make a nice visual for the users to check through their data based on entering a date.
Many thanks

Creating Relationships while avoiding ambiguities

I have a flat table like this,
R# Cat SWN CWN CompBy ReqBy Department
1 A 1 1 Team A Team B Department 1
2 A 1 3 Team A Team B Department 1
3 B 1 3 Team A Team B Department 1
4 B 2 3 Team A Team C Department 1
5 B 2 3 Team D Team C Department 2
6 C 2 2 Team D Team C Department 2
R# indicates the RequestNumber,
Cat# indicates the Category,
SWN indicates the Submitted Week Number,
CWN indicates the Completed Week Number,
CompBy indicates Completed By,
ReqBy Indicates Requested By,
Department Indicates Department Name,
I would like to create a data model that avoids ambiguity and at the same time allows me to report on Category, SWN, CWN (needs to be only a week number), CompBY, ReqBy, Department through a single filter.
For example, the dashboard will have a single filter choice to select a week number.If that week number is selected, it will show the details of these requests from submitted and completed week number. I understand this requires the creation of a calendar table or something like that.
I am looking for a data-model that explains the cardinality and direction(Single or both). If possible, kindly post the PBIX file and repost the link here.
What I have tried: Not able to establish one of the four connections
Update: Providing a bounty for this question because I would like to see how does the Star schema will look like for this flat table.
One of the reason I am looking for a star schema over a flat table is - For example, a restaurant menu is a dimension and the purchased food is a fact. If you combined these into one table, how would you identify which food has never been ordered? For that matter, prior to your first order, how would you identify what food was available on the menu?
The scope of your question is rather unclear, so I'm just addressing this part of the post:
the dashboard will have a single filter choice to select a week number. If that week number is selected, it will show the details of these requests from submitted and completed week number.
One way to get OR logic is to use a disconnected parameter table and write your measures using the parameters selected. For example, consider this schema:
If you put WN on a slicer, then you can write a measure to filter the table based on the number selected.
WN Filter = IF(COUNTROWS(
INTERSECT(
VALUES(WeekDimension[WN]),
UNION(
VALUES(MasterTable[SWN]),
VALUES(MasterTable[CWN])))) > 0, 1, 0)
Then if you use that measure as a visual level filter, you can see all the records that correspond to your WN selection.
If you can clarify your question to more closely approach a mcve, then you'll likely get better responses. I can't quite determine the specific idea you're having trouble with.