SSAS - cube filtering on import - powerbi

I am new to SSAS and after trying for hours to solve this problem I asking here.
I have a msOLAP cube that I want to import into SSAS PowerBI
but due to large database I want to pre-filter it befor importing.
The cube has measures in cpe_fact table and many other dimensions i.e. dim_time, dim_product, dim_material etc...
What I am trying to achieve is getting all the fields from the fact table joined with a subset of dimensions (i.e. only dim_time and dim_product) and filter them by date (i.e. cpe_fact.sale_date < now-6 month)
I tried to put this as MDX query but could not get any data by usin this MDX:
SELECT
{ [CPE_FACT].[MAIN].[SALES_Q]} ON COLUMNS,
{ [Selected_Date].[POSTING_DATE] } ON ROWS
FROM [CPE_Analytics]
I get this error: cube either does not exist or has not been processed evewn before I had a chance to define the WHERE part.
I tried DAX :
evaluate(filter('CPE_FACT', [AGENT] >= "26003"))
it worked but only for CPE_FACT table but i didnt understant how to join with the other dimensions...
My Question: How can I import some Facts Join Few dimentions from the Cube?
Example SSAS Connection -

Instead of using an MDX/DAX query use Power Query editor in two steps :
chose the tables you want to import (cpe_fact,dim_time and dim_product).
apply a filter on the date column in the fact table (cpe_fact) to load the desired resultes.
visit : https://radacad.com/only-get-the-last-few-periods-of-data-into-power-bi-using-power-query-filtering

Related

Making column reference via slicer

I have a table with two choices 'FLOW_CONTEXT' and 'TEST_NAME'.
I want to let the user select one of these values using a slicer. I then want to have a calculated formula point to either the 'FLOW_CONTEXT' or the 'TEST_NAME' column in another table. There is a 1:1 relationship between the 'FLOW_CONTEXT' and the 'TEST_NAME' columns in the table.
Here is the column formula I have, which always defaults to false, even though the SELECTEDVALUE part of the IF statement does work (checked via a card):
COLUMN_POINTER = IF(
SELECTEDVALUE(TEST_NAME_FIELD[TEST_NAME_FIELD]) = "FLOW_CONTEXT",
CCD_BINNING_TEST_RESULTS_LAST_RANK[FLOW_CONTEXT],
CCD_BINNING_TEST_RESULTS_LAST_RANK[TEST_NAME]
)
I have tried doing this with a measure but measures only see non-categorical columns. Thx much.
Columns are only calculated at refresh time - they do not respond to slicers filters in this way. You cannot re-calculate a column based on a selected value in a table visual.
You need to transform your use-case into a measure-friendly approach.

MDX filtering in PowerBI

I'm importing data from a cube but since the whole cube is too big for Power BI I have to use MDX to filter it out.
I'm new to MDX and so far I've come up with this code:
SELECT NON EMPTY Hierarchize({DrilldownLevel({[Stores POS].[Type hierarchy].[All types]},,,INCLUDE_CALC_MEMBERS)}) ON COLUMNS , NON EMPTY Hierarchize({DrilldownLevel({[Stores POS].[POS hierarchy].[All POS]},,,INCLUDE_CALC_MEMBERS)}) ON ROWS FROM [Receipts Cube] WHERE ([Time].[Time].[Calendar Year].&[2020],[Measures].[Count of Receipts])
This all works in SSMS the way it has to. Left column with store names etc. But when I copy that code to PBI the stores names disappear and instead I have "[Stores POS].[POS hierarchy].[All POS]" for each value where a Store name should be. I'm guessing PBI doesn't like hierarchizing but when trying to remove it I can't get the code to work at all.
SELECT
NON EMPTY {[Stores POS].[Type hierarchy].[WinPOS], [Stores POS].[Type hierarchy].[SelfCheckout]} ON COLUMNS,
NON EMPTY {[Stores POS].[POS hierarchy].[Store]} ON ROWS
FROM [Receipts Cube])
WHERE ([Time].[Time].[Calendar Year].&[2020],[Measures].[Count of Receipts])

Conditionally hide column in a Matrix - Powerbi desktop

Has anyone found a cool solution for this problem?
I have a table like below.
I want to completely hide the pre or post columns if there are no values in them. So in the screenshot the desired result would be that the first two Post columns, for Oct and Nov, would be hidden and the Pre column for Jan would also be hidden.
I read about using visual level filters but as it is a matrix and not a singular column this doesn't work.
The amount value is already using a switch for measure selection.
In case you can't see the image. Rows are categories, columns has date and I have two measures one called pre and one called post. Most and the time if pre is full, post is empty vice versa except for 1 or 2 months overlap
It's not great but I have a workaround.
Create a new dimension table DimMeasure (with no relationships):
Measure
--------
Pre
Post
Write a switching measure that picks [Pre] or [Post] based on the new dimension.
PrePost = IF ( SELECTEDVALUE ( DimMeasure[Measure] ) = "Pre", [Pre], [Post] )
Add DimMeasure to you columns in the matrix below the month and [PrePost] to the values instead of the two component measures.

Obtain MAX of column and display for each row

I'm trying to obtain the MAX of a particular column in a Power BI Report and place this as a new Measure within each ROW of the same dataset. Please see the example below.
Is this possible in DAX and via DirectQuery/LiveConnection? The report is pointing to a tabular model but due to outside factors the measure must be created in the report.
Thanks
You can accomplish this a few ways. Essentially, you need override the filter context so that the MAX function isn't just running over whatever slice you're showing in the visual. Using CALCULATE or the iterator function MAXX, set the wrap the table in the ALL() function to override the context and calculate max over all rows.
= CALCULATE(MAX([Calendar`Year]), ALL('Smithfield_Fiscal_Calendar'))
or
= MAXX(ALL('Smithfield_Fiscal_Calendar'), [Calendar`Year])
To get the breakout by date, you'll need to include a Date table in your model. PowerBI makes this possible with a few different DAX options. As an example, go to your Model tab, click 'New Table' and put in the following expression:
MyCalendar = CALENDAR(DATE(2019,1,1), DATE (2019,1,10))
This is a little trivial -- you'd want to use a useful range of dates but this one matches your example above. Next, add a column to [MyCalendar]
CalendarMonthYear = month([date]) & "-" & year([date])
Go to your budget table and add a similar field
BudgetMonthYear = month([date]) & "-" & year([date])
Go into your Model view and create a relationship between CalendarMonthYear and BudgetMonthYear. This will associate every date in the date table with the particular budget row from your budget table.
Hope it helps.

Trying to Reorder Columns in Data View in Power BI

Is there a way I can reorder columns in 'Data View' within Power BI? I tried doing it in Power Query first but when the data loads into the table, the columns automatically rearrange.
Edit after comment.
There is easy fix to enforce column order just as in Power Query:
In Power Query Editor > Disable Query Load. Close and Apply.
Open the Query Editor again, enable the Query Load. Refresh the Query. Then Close and Apply.
Answer to misunderstood question.
This may be interesting solution in M PowerQuery. The function below let you reorder columns by only stating few columns from the whole set of columns. Add this in blank query and rename it to FnReorderColumnsSubset.
(tbl as table, reorderedColumns as list, offset as number) as table =>
Table.ReorderColumns
(
tbl,
List.InsertRange
(
List.Difference
(
Table.ColumnNames(tbl),
reorderedColumns
),
offset,
reorderedColumns
)
)
Use it as this:
= FnReorderColumnsSubset( Source, { "Region", "RegionManager", "HeadCount" }, 0 )
Found it here:
https://datachant.com/2017/01/18/power-bi-pitfall-4/
It is extremely stupid way, but it is working - i found it by accident:
In edit query view remove the column, then save changes. You will see that in data view that column was removed as well.
Now again in edit query view remove from applied steps the action that removed the column. Save it again.
You will see that removed previously column was added to the end of the table.
This way you can arrange your columns to have it the way you want it in data view.
Hope it helped.
I don't know that you can rearrange an existing table, but if you re-create it as a new table, you can pick the order you want.
NewTable =
SELECTCOLUMNS (
OldTable,
"Column1", OldTable[Column1],
"Column2", OldTable[Column2],
"Column3", OldTable[Column3]
)
I think most here have misunderstood the problem, except #Jacko. So far as I know it is now possible to re-arrange columns in Power Query and load to the model and the table will load in the column order you specified in PQ. The problem is in dataview in the modelling layer of PBi. Here you can add many calculated columns, but, any new column you add is always placed at far right and can't be moved. Yes, I know about SELECTCOLUMNS but it isn't a solution as the new table does not have the editable formulae. A solution is a drag and drop feature of some sort. PBi users are still waiting for it despite the problem being flagged in MS Forums some years ago. No progress TIKO other than the limp SELECTCOLUMNS solution.