I am writing a DAX query for use in SSRS dataset.
I have a requirement to calculate the date difference between a dimension date column and today(), then group these into segments, I.e. 1-7 days, 7-10 days etc - and return the segment for each row in the table (with other additional filters)
As it’s for use in SSRS I’m using EVALUATE(SUMMARIZECOLUMNS
A switch statement won’t work for value ranges in DAX and when I use nested If statement the query uses all available memory.
Is there a function I can use for to group by the calculated column into segments.
Any advise appreciated.
Thanks
W
Related
I have a table in Excel, utilizing Power Pivot that I then display/filter using a Pivot Table. Within my dataset, calculating a ratio within Power Pivot that "sums" correctly in the pivot table based on slicers is fine - this utilizes a SUMX(Cost)/SUMX(Total) and everything works fine. By sums correctly, I mean if I further break down the data set based on Region/State/Product/Employee, all those Rows sum up correctly for the ratio percentage.
The dataset is filtered based on a single month or range of months. The result of this works fine for either the single month or range of Months. What I'm trying to do is within my Pivot Table, show a current month ratio AND a year to date ratio. I've tried messing around with equations I've found online, but nothing seems to work. This includes the following attempts:
=CALCULATE([Cost],[ProductID]="224594")/CALCULATE([Total],[ProductID]="224594")
=SUMX (FILTER(ALL('TableName'),PATHCONTAINS ('TableName'[ProductID], EARLIER('TableName'[ProductID]))),'TableName'[Cost]) / SUMX(FILTER(ALL('TableName'),PATHCONTAINS('TableName'[ProductID], EARLIER ('TableName'[ProductID]))),'TableName'[Total])
I need the "sumifs" to sum the cost for Product A for all months divided by the sum of total for Product A for all months. I do not want to hard code in the the Product ID into the equation, but simply sum all previous records for that product, but I can't seem to get this to work.
Any suggestions?
Sample Data Set
I used the calculate and filter functions in a column instead of trying to use them in a measure, which fixed the problem.
I'm trying to create a calculated column based on a derived measure in SSAS cube, this measure which will count the number of cases per order so for one order if it has 3 cases it will have the value 3.
Now I'm trying to create a bucket attribute which says 1caseOrder,2caseOrder,3caseOrder,3+caseOrder. I tried the below one
IF([nrofcase] = 1, "nrofcase[1]", IF([nrofcase] = 2, "nrofcase[2]",
IF([nrofcase] = 3, "nrofcase[3]", "nrofcase[>3]") )
But it doesn't work as expected, when the level of the report is changed from qtr to week it was suppose to recalculate on different level.
Please let me know if it case work.
Calculated columns are static. When the column is added and when the table is processed, the value is calculated and stored. The only way for the value to change is to reprocess the model. If the formula refers to a DAX measure, it will use the measure without any of the context from the report (eg. no row filters or slicers, etc.).
Think of it this way:
Calculated column is a fact about a row that doesn't change. It is known just by looking at a single row. An example of this is Cost = [Quantity] * [Unit Price]. Cost never changes and is known by looking at the Quantity and Unit Price columns. It doesn't matter what filters or context are in the report. Cost doesn't change.
A measure is a fact about a table. You have to look at multiple rows to calculate its value. An example is Total Cost = SUM(Sales[Cost]). You want this value to change depending on the context of time, region, product, etc., so it's value is not stored but calculated dynamically in the report.
It sounds like for your data, there are multiple rows that tell you the number of cases per order, so this is a measure. Use a measure instead of a calculated column.
I am trying to create a "meetingroom occupancy" matrix in Power BI. The raw data contains bookings per day per Room. The maximum daily available time per room is 12 hours. I have created a Date Dimension Table for the dates.
I have tried to change datatypes, added the available time column in the query editor, added the available time as DAX column and as calculated measure, but all with no success. I have changed the available time for Room B to 1, and the result of the Subtotal was 13, so it looks like subtotals is only summing unique values, but I do not know how to solve this.
Could someone please explain to me what is happening and how I could solve this?
The input data is as follows:
And my Date_Dimension is as follows:
This is the current and desired result:
I am currently working on a problem that requires iterating a table and finding the distance between the latitudes and longitudes of each entry in the table.Is there a way to iterate the table using DAX Query in Power BI?
The first hints that you have to look for are:
add calculated columns to a table to get what you want at row level,
use X functions such as SUMX, AVERAGEX, COUNTX (there are lots of them) to get aggregates.
The stack is SQL relational tables into SQL 2014 Tabular consumed by Excel 2010.
The Tabular model grain is one row per purchase order (PO) line item. Each row has a dollar value (item cost$) which is used for a sum measure (total cost$).
A Time Intelligence Date table is related so the sum of total costs$ for a year can be determined for example.
How best to implement a month to date aggregate? Should a DAX query against the model calculate the MTD on the fly as I pull the data in Excel? Or is there a way to implement directly into the model at the PO line item grain?
I personally would stick a calculated measure in the model itself using TOTALMTD() - you could always just use SQL and do it in the back end though. Calculated measures are generally pretty efficient - your model would have to be huge before you start seeing performance issues with them so I wouldn't worry too much