Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hello everyone.
I have the following scenario:
- In the first calculated column i want the date of the newest service existing in a period >= [revenuedate - 405 days] and <= [revenuedate - 40]
- I need the newest date, because in the 365 days window, i can have 0 or 1 or 2 or more ocurrences of different services for a given client
- The newest date to get is based on a hierarchy of the services, where 1 is the highest priority, as seen on the screenshot
- In the second calculated column i would like to get the service name related to the date returned in the first created calculated column
I will upload the pbi file to help understand better my doubts. In this file the calculated columns are created and their names are "MAXSERVICE YEARMONTH" and "SERVICE NAME"
pbi file: https://drive.google.com/open?id=0B8Aq8DhGApJqWDZlLTdQYnFibDQ
Solved! Go to Solution.
It seens to work this way in the test data base that i shared with you. (I will need to test this on the actual data base to be 100%):
Column =
VAR MINH =
MINX(
FILTER(
'BASE SERVICES';
'BASE SERVICES'[CLIENT] = EARLIER(BASEDATA[CLIENT])
&& 'BASE SERVICES'[DATE] >= EARLIER('BASEDATA'[REVENUEDATE]) - 405
&& 'BASE SERVICES'[DATE] < EARLIER('BASEDATA'[REVENUEDATE]) - 40);
'BASE SERVICES'[HIERARCHY])
RETURN
MAXX(
FILTER(
'BASE SERVICES';
'BASE SERVICES'[CLIENT] = EARLIER('BASEDATA'[CLIENT]) &&
'BASE SERVICES'[DATE] >= EARLIER('BASEDATA'[REVENUEDATE]) - 405 &&
'BASE SERVICES'[DATE] < EARLIER('BASEDATA'[REVENUEDATE]) - 40
&& 'BASE SERVICES'[HIERARCHY] = MINH);
DATE(YEAR('BASE SERVICES'[DATE]);MONTH('BASE SERVICES'[DATE]);1))
Question: Why it doesnt work this way??
Column =
MAXX(
FILTER(
'BASE SERVICES';
'BASE SERVICES'[CLIENT] = EARLIER('BASEDATA'[CLIENT]) &&
'BASE SERVICES'[DATE] >= EARLIER('BASEDATA'[REVENUEDATE]) - 405 &&
'BASE SERVICES'[DATE] < EARLIER('BASEDATA'[REVENUEDATE]) - 40
&& 'BASE SERVICES'[HIERARCHY] = MIN('BASE SERVICES'[HIERARCHY]);
DATE(YEAR('BASE SERVICES'[DATE]);MONTH('BASE SERVICES'[DATE]);1))
HI @bolabuga
How close is this calculated column for your first requirement?
I'm not clear what you need to do with Hierarchy
Column =
MAXX(
FILTER(
'BASE SERVICES',
'BASE SERVICES'[CLIENT] = EARLIER('BASEDATA'[CLIENT]) &&
'BASE SERVICES'[DATE] >= EARLIER('BASEDATA'[REVENUEDATE]) - 405 &&
'BASE SERVICES'[DATE] < EARLIER('BASEDATA'[REVENUEDATE]) - 40
),
'BASE SERVICES'[DATE])
It seens to work this way in the test data base that i shared with you. (I will need to test this on the actual data base to be 100%):
Column =
VAR MINH =
MINX(
FILTER(
'BASE SERVICES';
'BASE SERVICES'[CLIENT] = EARLIER(BASEDATA[CLIENT])
&& 'BASE SERVICES'[DATE] >= EARLIER('BASEDATA'[REVENUEDATE]) - 405
&& 'BASE SERVICES'[DATE] < EARLIER('BASEDATA'[REVENUEDATE]) - 40);
'BASE SERVICES'[HIERARCHY])
RETURN
MAXX(
FILTER(
'BASE SERVICES';
'BASE SERVICES'[CLIENT] = EARLIER('BASEDATA'[CLIENT]) &&
'BASE SERVICES'[DATE] >= EARLIER('BASEDATA'[REVENUEDATE]) - 405 &&
'BASE SERVICES'[DATE] < EARLIER('BASEDATA'[REVENUEDATE]) - 40
&& 'BASE SERVICES'[HIERARCHY] = MINH);
DATE(YEAR('BASE SERVICES'[DATE]);MONTH('BASE SERVICES'[DATE]);1))
Question: Why it doesnt work this way??
Column =
MAXX(
FILTER(
'BASE SERVICES';
'BASE SERVICES'[CLIENT] = EARLIER('BASEDATA'[CLIENT]) &&
'BASE SERVICES'[DATE] >= EARLIER('BASEDATA'[REVENUEDATE]) - 405 &&
'BASE SERVICES'[DATE] < EARLIER('BASEDATA'[REVENUEDATE]) - 40
&& 'BASE SERVICES'[HIERARCHY] = MIN('BASE SERVICES'[HIERARCHY]);
DATE(YEAR('BASE SERVICES'[DATE]);MONTH('BASE SERVICES'[DATE]);1))
Hi @bolabuga
In your second example the like that goes
BASE SERVICES'[HIERARCHY] = MIN('BASE SERVICES'[HIERARCHY]);is pretty much dropping down to a single line. If you want to use a single statement, you'd need to nest your filter statements, but you will still end up with a similar amount of code - and no performance gain.
Thks Phil for the help.
Pratical Dax are certainly in my TARGET, but before that i need to finish my reading of "definitive guide to dax", which i bought recently.
Thks for the reply phil.
Hierarchy is really important.
Imagine this scenario for 1 client:
My revenue date is 11/12/17 (dd/mm/yy)
I need filter service table looking for services on that client number, based on the revenuedate.
Looking into a period of 405 days before revenue date.
Lets supose i have 3 services located in the 405 days period, after the filters happen:
- service A in 10/01/17 (dd/mm/yy)
- service B in 15/03/17 (dd/mm/yy)
- service D in 17/05/17 (dd/mm/yy)
In the revenue table i can only have 1 date from those 3 services as a viable result per client for the calculated column "MAXSERVICE YEARMONTH", and here is where i need the hierarchy, i want to follow the result of the most important service based in the hierarchy table, and not always the most important service is the newest one. In the scenario above, even if i have newer services (B,D), i want as result the date of the "A" service.
In fewer words, i need to filter service table in such a way, where i alwas get the "maximum date" of the "minimum Hierarchy" available on the context (client number and period of days).
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 48 | |
| 45 | |
| 41 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 69 | |
| 63 | |
| 32 | |
| 31 | |
| 25 |