Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Does any one see why the following code works for ID 26 and 21, but not 27 and 15? It probably has something to do with timestamps being identical for some entries, as the code works for instances where the correct output does not have a duplicated timestamp. The extract is the last ADDCOLUMN comand of a much longer code for a calculated table. The rest of the code works perfectly up to this point. Any quick and easy soutions would be much aprreciated!
EXTRACT:
[...]
Current Level English | Current Level German | Current Level Italian | Current Level Ladin | EXLO ID | L1 | L2 |
B2 | B2 | C1 | 27 | Italian | Italian | |
C1 | C1 | C1 | 26 | Italian | German | |
C1 | C1 | C1 | 15 | Italian | Italian | |
B2 | B2 | C1 | 21 | Italian | German |
All Language Certifications (has many more rows)
Cert EXLO ID | Cert Date | Cert Language | Cert Language Order Level | Cert Institute ID | Cert Exam Board |
15 | 23.05.14 14:29 | English | 8 | 67 | Other |
15 | 05.05.14 18:42 | Italian | 8 | 37 | High School-University |
15 | 23.05.14 14:27 | German | 8 | 26 | Province of Bozen-Bolzano |
15 | 23.05.14 14:27 | Italian | 8 | 26 | Province of Bozen-Bolzano |
21 | 29.04.15 11:48 | Italian | 8 | 37 | High School-University |
21 | 08.05.15 00:00 | German | 6 | 1 | UNIBZ |
21 | 12.01.21 00:00 | English | 6 | 1 | UNIBZ |
26 | 10.03.16 11:35 | German | 8 | 31 | Goethe Institut |
26 | 10.03.16 11:22 | Italian | 8 | 37 | High School-University |
26 | 10.03.16 11:49 | English | 8 | 62 | Cambridge |
26 | 10.03.16 11:46 | German | 8 | 26 | Province of Bozen-Bolzano |
26 | 10.03.16 11:46 | Italian | 8 | 26 | Province of Bozen-Bolzano |
27 | 09.04.16 14:50 | Italian | 8 | 37 | High School-University |
27 | 09.04.16 14:56 | Italian | 6 | 26 | Province of Bozen-Bolzano |
27 | 09.04.16 14:56 | German | 6 | 26 | Province of Bozen-Bolzano |
27 | 09.04.16 14:56 | English | 6 | 62 | Cambridge |
The problem is that L1 and L2 cannot be identical. 15 should have an L2 of "German" and 17 could be "English" or "German" based on the logic at hand. (I will improve that part later.)
Thanks in advance!!
This seems to do the trick. But I will offer the "accepted solution" to anyone who can find errors or optimize:
I think using variables will make it easier to keep track of what's going on.
Here's a refactoring attempt using some variables:
a =
VAR _EXLO = [EXLO ID]
VAR _Level = [German Current Level Order]
VAR _Date1 =
CALCULATE (
MIN ( 'All Language Certifications'[Cert Date] ),
ALL ( 'All Language Certifications' ),
'All Language Certifications'[Cert EXLO ID] = _EXLO,
'All Language Certifications'[Cert Language Order Level] = _Level,
'All Language Certifications'[Cert Language] <> "Italian"
)
VAR _1 =
CALCULATE (
SELECTEDVALUE ( 'All Language Certifications'[Cert Language] ),
KEEPFILTERS ( 'All Language Certifications'[Cert EXLO ID] = _EXLO ),
KEEPFILTERS ( 'All Language Certifications'[Cert Language Order Level] = _Level ),
KEEPFILTERS ( 'All Language Certifications'[Cert Language] <> "Italian" ),
KEEPFILTERS ( 'All Language Certifications'[Cert Date] = _Date1 )
)
VAR _Date2 =
CALCULATE (
MIN ( 'All Language Certifications'[Cert Date] ),
ALL ( 'All Language Certifications' ),
'All Language Certifications'[Cert EXLO ID] = _EXLO,
'All Language Certifications'[Cert Language Order Level] = _Level,
'All Language Certifications'[Cert Language] <> "Italian",
'All Language Certifications'[Cert Exam Board] = "Province of Bozen-Bolzano"
)
VAR _2 =
CALCULATE (
SELECTEDVALUE ( 'All Language Certifications'[Cert Language] ),
KEEPFILTERS ( 'All Language Certifications'[Cert EXLO ID] = _EXLO ),
KEEPFILTERS ( 'All Language Certifications'[Cert Language Order Level] = _Level ),
KEEPFILTERS ( 'All Language Certifications'[Cert Language] <> "Italian" ),
KEEPFILTERS ( 'All Language Certifications'[Cert Exam Board] = "Province of Bozen-Bolzano" ),
KEEPFILTERS ( 'All Language Certifications'[Cert Date] = _Date2 )
)
RETURN
IF (
[L1] = "Italian"
&& NOT ( [Current Level English] = "unknown" )
&& NOT ( [Current Level German] = "unknown" )
&& ISBLANK ( [Current Level Ladin] )
&& [English Current Level Order] = _Level,
IF ( ISBLANK ( _1 ), _2, _1 )
)
Thanks for the suggestion. Something like this would reduce the lines of code and improve performance. Unfortunately, it will not work. Table1 does not exist as a table in the data model. It is a table expression in the calculated table code. (Apologies if this was not clear from my posts.) So certain functions, like SELECTCOLUMNS() and ADDCOLUMNS() can be used to build upon it, but other more basic functions cannot. For instance I cannot create the first three variables, as [EXLO ID] and [German Current Level Order] cannot be found. Maybe there is a way to create these as a measure in the model?
Maybe I have figured it out... both the table and the MIN() function need to be filtered...
NOTE: The "order levels" are in a saved table, but not included the returned table. C1 = 8 and B2 = 6.
User | Count |
---|---|
57 | |
21 | |
21 | |
19 | |
16 |
User | Count |
---|---|
86 | |
84 | |
52 | |
37 | |
23 |