How to sort a numeric dimension in ssas - ssas

In one of my dimensions I have 4 columns with the data type tinyint but in ssas after processing the cube, its been assigned the data type system.byte. I dont know it did that. And because of this my data sort is like 1, 10, 2 etc. but I want it to be 1, 2, 3 etc. How can I overcome this issue?

In the dimension designer select each attribute. Then set OrderBy=Key. Redeploy.

Related

Big query Pivoting with a specific requirement

I have used pivot in big query, but here is a specific use case and the data that I need to show in looker. I am trying the similar option in looker but wanted to know if I can just show this in big query.
This is how my data (Sample) in BIG QUERY table is:
The output should be as below:
If you look at it, it's pivoting but I need to assign the column names as shown (for the specific range) and for the range 6 and more, I need to add the pivot columns data into one.
I don't see pivot index or something like this in BIG_QUERY. Was thinking if there is a way to sum up the column data after pivot index 6 or so? Any suggestions how to achieve this?
Hope below approach would be helpful,
SELECT * FROM (
SELECT Node, bucket, total_code
FROM sample, UNNEST([RANGE_BUCKET(data1, [1, 2, 3, 4, 5, 6, 7])]) bucket
) PIVOT (SUM(total_code) `range` FOR bucket IN (1, 2, 3, 4, 5, 6, 7));
output:
RANGE_BUCKET - https://cloud.google.com/bigquery/docs/reference/standard-sql/mathematical_functions#range_bucket

Power BI / DAX: Sort Calculated Table by Calculated Column

I have a Power BI data model with a DAX calculated table used as a dimension that is calculated with VALUES from a fact table with multiple occurrences of each value, so it is a 1:M relationship.
In my report I want to use the calculated table values as a slicer with the options presented in a specific order other than alphabetical. Therefore in the calculated table, I created a calculated column that assigns a number to each row based on a SWITCH function. However, when I then try to "Sort by Column" in Power BI, it throws an error indicating that it is a circular reference. How else can I define the sort order?
Here is an example data/calculated tables:
'Source' fact table:
Dimension_Values
a_order_third
a_order_third
b_order_first
b_order_first
c_order_second
c_order_second
Calculated_Dim_Table = VALUES('Source'[Dimension_Values])
Dimension_Values
a_order_third
b_order_first
c_order_second
Calculated_Order_Column = SWITCH('Calculated_Dim_Table'[Dimension_Values],"b_order_first",1,"c_order_second",2,"a_order_third",3)
*Sort 'Calculated_Dim_Table'[Dimension_Values] by 'Calculated_Dim_Table[Calculated_Order_Column] so that desired output is
Dimension_Values
Calculated_Order_Column
b_order_first
1
c_order_second
2
a_order_third
3
Issue: Power BI is saying this is creating a circular dependency - is there another way to define the sort order of a column without referencing it to avoid the circular dependency?
I think it throws an circular reference error, caused DAX internally decides the the order of execution. In this case, DAX wants to sort the dimension values upon loading, but it can't cause it depends on a calculated column thst in turn depends on dimension values. So it is a circular reference indeed. I would advise you to this in PQ and then load both the tables and then you can do the sorting in t2 with no trouble.

MDX for getting dimensions of a cube?

Assume that a cube named MyCube has 2 dimensions, and I want to build an MDX SELECT statement without knowing the name of the dimensions but I have a list of elements with one element from each dimension:
SELECT [ELEM X from first dimension] ON 0, [ELEM Y from second dimension] ON 1
FROM [MyCube]
Alternatively is there a function that will return the list of all dimensions and that I can use to built my MDX?
Yes, you can query a dimension without knowing its exact name. You don't even have to know the names of any member, as this example shows. Just be careful in case you are returned a grid of 10000 x 10000 results!
SELECT
{Dimensions(0).Levels(0).members} ON ROWS,
{Dimensions(1).Levels(0).members} ON COLUMNS
FROM [Sales]
It may also be useful to use .members(0) or [Measures].allMembers to specify items where the name is not known.

Create a Calculated Member to remove need to load pre calculated measure

I am trying to replicate the following sql statement into MDX so that I can create a calculated member in the cube using the base loaded members instead of having to calculate it outside the cube in the table and then loading it
SUM(CASE WHEN ((A.SALES_TYPE_CD = 1) AND (A.REG_SALES=0))
THEN A.WIN_SALES
ELSE 0
END) AS Z_SALES
I am currently loading SALES_TYPE_CD as a dimension and REG_SALES and WIN_SALES as measures.
I also have a few other dimensions in the cube but for simplicity, lets just say I have 2 other dimensions, LOCATION and ITEM
The dimension has LOCATION has 3 levels, "Region"->"District"->"Store", ordered from top to bottom level.
The dimension has ITEM has 3 levels, "CLASS"->"SUBCLASS"->"SKU", ordered from top to bottom level.
The dimension has SALES TYPE has 2 levels, "SALES_TYPE_GROUP"->"SALES_TYPE_CD", ordered from top to bottom level.
I know that I cannot create a simple calculated member in the cube which crossjoins the "SALES_TYPE" dimension with another dimension to get the answer I want.
I would think that it would be a more complicated MDX statement something like :
CREATE MEMBER CURRENTCUBE.[Measures].[Z_Sales]
AS 'sum(filter(crossjoin(leaves(), [Sales Type].[Sales Type].
[Sales_Type_CD].&[1]), [Measures].[REG_SALES]=0),[Measures].
[WIN_SALES])',
FORMAT_STRING = '#,#',
VISIBLE = 1 ;
But this does not seem to return the desired result.
What would be the proper MDX code to generate the desired result?
I did a bunch of testing with the data and I now know that there is no way I can get the right answer by using MDX alone in this scenario. Like "Greg" and "Tab" suggested, the only way would be to have reg sales as a dimension. Since this is a measure, that is out of the question because of the large number of possibilities for the value which has a data type of decimal (18,2)
Thanks for taking the time to answer the question.

SQL Reporting Services - Subreports Broken into multiple columns

I inherited an SQL Reporting Services .rdl project from somebody and need help fixing some functionality.
In each row of the report, there is a subreport. In order to save space the subreport is divided into 3. Such that in each row of the report, it splits the data of the subreport into 3 smaller tables. Right now, it fills these 3 subreports horizontally. (ie. if the result has 9 values, the first subtable will have 1, 4 & 7, the second subtable will have 2, 5 & 8, etc)
Is there a way to have it fill the subtables vertically? (ie. the first subtable would have 1,2 & 3)
Thanks!
By default, the multi-column reports should fill vertically. In fact, there isnt even an option to fill horizontally so i'd like to know how it is being done. Perhaps the underlying query has been modified?
In fact, I took a deeper look into the query and it turns out that the column number is being passed as a report parameter and the results are being reordered using a modulo on the column number. I don't have it with me right now, so I don't have the exact syntax.
More info for anyone trying to do this:
it turns out that the subreport query gerates a column which indicates the row number
ROW_NUMBER() OVER (PARTITION BY columnName ORDER BY otherColumn) AS RowNumber
Then in the report, the subreport is included 3 times. Each subreport has a report parameter called Column, the first one is of value 1, the second 2 and the last one 0. The subreport then has a filter on it
=RowNumber Mod 3 = Column
that way the subreport results are divided into 3 supreports that can all be placed on the same row to save space.