{"id":490,"date":"2016-04-01T17:06:16","date_gmt":"2016-04-01T16:06:16","guid":{"rendered":"http:\/\/ubiquis.co.uk\/?p=402"},"modified":"2020-04-24T12:23:31","modified_gmt":"2020-04-24T11:23:31","slug":"fizz-buzz","status":"publish","type":"post","link":"https:\/\/ubiquis.co.uk\/fizz-buzz\/","title":{"rendered":"Fizz buzz"},"content":{"rendered":"
So, today is the day everybody should blog about something really stupid…<\/p>\n
Ok, so here’s ours: Fizz Buzz in MDX.<\/p>\n
Fizz Buzz<\/a>, for those that don’t know it, is one of those “tests” interviewers love to see whether a candidate can code or not. It’s useless as pretty much everybody knows it by now, but that’s besides the point.<\/p>\n There are a number of examples of “how to implement Fizz Buzz in language X”. Some are quite lame, others more impressive<\/a>.<\/p>\n So, in the spirit of April Fools, here’s our Fizz Buzz implementation, in MDX. Run it against SteelWheelsSales, or any cube that has a dimension called set NUMBERS as Generate( DIGITS, Generate( DIGITS, DIGITS, ALL), ALL)<\/p>\n member [Measures].[Ordinal] as NUMBERS.CurrentOrdinal<\/p>\n member [Measures].[Fizz] as Iif( [Measures].[Ordinal] = Round( [Measures].[Ordinal]\/3 ) *3, \"fizz\", \"\") member [Measures].[FizzBuzz] as Iif( [Measures].[FB] = \"\", [Measures].[Ordinal], [Measures].[FB] )<\/p>\n SELECT <\/code> Although a trivial and quite futile exercise, it does have one feature that is worth mentioning: the So, today is the day everybody should blog about something really stupid… Ok, so here’s ours: Fizz Buzz in MDX. Fizz Buzz, for those that don’t know it, is one of those “tests” interviewers love to see whether a candidate can code or not. It’s useless as pretty much everybody knows it by now, but […]<\/p>\n","protected":false},"author":4,"featured_media":438,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,14],"tags":[],"yoast_head":"\n[Time]<\/code>.<\/p>\n
\nWITH<\/code><\/p>\n member [Time].[0] as 0
\nmember [Time].[1] as 1
\nmember [Time].[2] as 2
\nmember [Time].[3] as 3
\nmember [Time].[4] as 4
\nmember [Time].[5] as 5
\nmember [Time].[6] as 6
\nmember [Time].[7] as 7
\nmember [Time].[8] as 8
\nmember [Time].[9] as 9
\nset DIGITS as { [Time].[0], [Time].[1], [Time].[2], [Time].[3], [Time].[4],
\n[Time].[5], [Time].[6], [Time].[7], [Time].[8], [Time].[9] }<\/p>\n
\nmember [Measures].[Buzz] as Iif( [Measures].[Ordinal] = Round( [Measures].[Ordinal]\/5 ) *5, \"buzz\", \"\")
\nmember [Measures].[FB] as [Measures].[Fizz] || [Measures].[Buzz]<\/p>\n
\nNUMBERS on Rows,
\n{ [Measures].[Ordinal], [Measures].[FizzBuzz] } on Columns<\/p>\nFROM
\n[SteelWheelsSales]
\n<\/code><\/p>\nAll<\/code> argument in the
Generate<\/code> function. Generate<\/a> applies each element of the first set to each element of the second set. However, without the
ALL<\/code> argument, duplicates from the resulting set are removed, which results in us getting only a 10 element set.<\/p>\n","protected":false},"excerpt":{"rendered":"