Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi All,
I have a table that contains data for years 2005 to 2018. I need to generate a sample of records for each year in the table. My working DAX expression looks like this:
Sample Table = UNION( SAMPLE( 10, FILTER('Consolidated Data', AND('Consolidated Data'[Year Commenced] = 2005, ISBLANK('Consolidated Data'[Year Completed]) = FALSE)), 'Consolidated Data'[Student ID] ), SAMPLE( 10, FILTER('Consolidated Data', AND('Consolidated Data'[Year Commenced] = 2006, ISBLANK('Consolidated Data'[Year Completed]) = FALSE)), 'Consolidated Data'[Student ID] ), SAMPLE( 10, FILTER('Consolidated Data', AND('Consolidated Data'[Year Commenced] = 2007, ISBLANK('Consolidated Data'[Year Completed]) = FALSE)), 'Consolidated Data'[Student ID] ) )
While this approach works, it feels wrong. I'm copying and pasting each call to the SAMPLE function and only changing the filter, and then using the UNION function to consolidate the returned records together into a single table.
Does anyone have any suggestions for an alternative approach?
With thanks.
-Corey
Solved! Go to Solution.
You could use a pattern like the following to avoid duplicating code, you then just add to the list of years that you are generating over (or you could use the GENERATESERIES() function to generate a continuous list of years)
Sample Table = SELECTCOLUMNS( GENERATE( {2005,2006,2007}, SAMPLE( 10, FILTER('Consolidated Data', AND('Consolidated Data'[Year Commenced] = [VALUE], ISBLANK('Consolidated Data'[Year Completed]) = FALSE)), 'Consolidated Data'[Student ID] ) ) , "Student ID" ,[Student ID] )
You could use a pattern like the following to avoid duplicating code, you then just add to the list of years that you are generating over (or you could use the GENERATESERIES() function to generate a continuous list of years)
Sample Table = SELECTCOLUMNS( GENERATE( {2005,2006,2007}, SAMPLE( 10, FILTER('Consolidated Data', AND('Consolidated Data'[Year Commenced] = [VALUE], ISBLANK('Consolidated Data'[Year Completed]) = FALSE)), 'Consolidated Data'[Student ID] ) ) , "Student ID" ,[Student ID] )
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
101 | |
86 | |
64 |