Calculated Measure with parameter - iccube-reporting

I have Measures like revenue, count_clickouts, count_impressions etc. and I would like to create calculated Measures with these Measures in a fixed time range (e.g. revenue_last_year).
Of course I can create one calculated Measure per possible combination of Measure and time range, but is it possible, to create one calculated Measure with parameters both in the name and the definition.
I tried something like this:
with member [Measure].[#{measure}_last_#{time_unit}] as sum(#{time_unit}.last_member.previous_member,#{measure})
So far I couldn't make it work. Is there an option to do this at all, or is this not implemented? We use IcCube reporting 5.2.2.

I use the [STATS] dimension for this, mostly for financial functions like [Prior Year], [Budget -/- Actuals], etc.
What you need to do is:
Measure: count_clicks - this is the measure with data linked to TIME
Then, create a one time [STATS] dimension, with [STATS] hierarchy.
Next, define the members you want, like [Prior Year]
Here is an example in the Sales schema, which is included by default in each icCube installation:
WITH CALCULATED MEMBER [Stats].[Stats-Time].[Prior Year] AS
([Stats].[Stats-Time].defaultmember, prevYear() ), SOLVE_ORDER = 1000
SELECT [Time].[Year].[Year] on 0
, {[Stats].[Stats-Time].[L-Stats-Time].&[Value], [Stats].[Stats-Time].[Prior Year]} on 1
FROM sales
WHERE [Measures].[Amount] * {[Customers].[Geography].[Region].[Europe].[Netherlands]}
Result:
The [Prior Year] will work with each Measure. Note to keep in mind the order sequence (SOLVE_ORDER) of the formulas.
Let me know if this works for you.

Related

power bi measure with 2 conditions 2 calculate

I am trying to create a measure which will calculate the Total Project Revenue
while I have 2 different projects. For each project there is a different calculation:
for Hourly project the calculation should be: Income * BillHours
for Retainer project the calculation should be: Income*TotalWorkinghours
I wrote the below DAX:
enter code here : Total project revenue = IF(max(DimProjects[ProjectType])="Hours",
max(FactWorkingHours[Income])[BillHours],max(FactWorkingHours[Income])*
[Total Working Hours])
the rows are calculated correctly but the total in the table is wrong
what should I fix in DAX so the total of all raw will correct as well.
The total Revenue should be 126,403.33
Thank you in advance
you can find here the table with the results
It's hard to say exactly what your measure is doing because, as written here, that is not a valid measure. I pasted it into the DAX Formatter, which I would recommend for formatting and pasting here into code blocks, and the measure was invalid. It would also be helpful to post the other measures this measure references, eg. [Bill Hours] and [Income Hours].
That being said, I think I can kind of tell what's going on. Your total is probably wrong because the filter context at the total level is being based of the condition where:
MAX ( DimProjects[ProjectType] ) = "Retainer" (or some other value not in your shared snippet)
That is because when you consider the MAX of a string, the higher alphabetical order is considered. Therefore, "Retainer" > "Hours". So at the total level, your table is outputting—more than likely, I can't be certain without more information—the false condition of your measure:
MAX ( FactWorkingHours[Income] ) * [Total Working Hours])
There is a better way to handle your intended outcome. IF statements, in the way you are attempting to use it, are rarely used in a calculated measure. You may be better off trying a calculated column without using the MAX functions. Again, I can't give an exact code recommendation without more context. Hope that sends you in the right direction!

How do I create measures that are not aggregated data?

I have a simple table which has a number(say sales) as one column which describes the sales done for a product. I also have ~25 products.
Now, I want to import this sales as a measure into cube. However, i am not sure what it's type and sql parameters should be. Setting the type to 'number' and sql to 'sales' gives error such as column "plan.sales" must appear in the GROUP BY clause or be used in an aggregate function.
What am I doing wrong?
Сould you please share the env vars, the cube.js file, and the data schema?
I also recommend you follow up through this guide. I think it might help.
I think you should add the sales column as a dimension, then you can define the aggregated measures like average sales or total of sales using the number of sales dimension.

Can a measure be created in Power BI that references two tables that share no relationship?

I'm trying to create a matrix table in Power BI to display the monthly rent projections for a number of properties. I thought I could simply create a measure that summed the rent from one table and then displayed it by month based on start and end date conditions, but it's been a while since I created any measures and I had forgotten that there needs to be a relationship between columns, among other things.
Data Model
A site can have more than one lease associated with it and a lease can have both car-parks and floors associated with it, of which there can be multiple.
In addition to the tables in the linked image, once I had sorted out what I thought would be the easy step I was going to add another table which includes the estimated percentage rent increase and the period in which the increase will occur.
I started out by trying to create a measure along the lines of the following:
Matrix Test =
IF (
HASONEVALUE ( Period[Month] ),
IF (
Period[Month] >= Leases[Custom Start Date],
SUM ( Floor_Rent[Annual Rent] ) / 12,
0
),
0
)
This would need to be expanded upon because the end date of a lease would also need to be taken into consideration.
As well as forgetting about the relationship requirements, I've forgotten how to deal with the issue of narrowing down to a single value within a column.
The result is supposed to be something that looks like this:
The blanks indicate a lease that starts in the future or ends within the time-frame displayed.
When I try linking the Leases table and the Period table on Leases[Start month for current term] and Period[Month] all I can get to is a table that shows the rent amount in the month the lease starts.
Is what I'm trying to achieve possible? If so, how do I accomplish the desired result?
Link to .pbix file
Solution
The direct answer to the title question is probably 'no', but while trying to figure out how I could use Pratik Bhavsar's LOOKUPVALUE suggestion I had a thought and performed a clumsy google search - power bi create table for each value in column - and found this post. By meddling with some of the DAX in said post I was able to come up with the following:
Test Table =
GENERATE(
SELECTCOLUMNS(
VALUES(Leases[Lease ID]),"Lease ID",[Lease ID]
),
SELECTCOLUMNS(
VALUES(Period[Month]),"Month",[Month]
)
)
The result is a table with each Lease ID mapped against each Month. I can't claim to understand exactly how the functions work, and it's not the outcome I thought I needed, but it allows me to achieve exactly what I set out to do.
I've accepted Pratik Bhavsar's answer because it effectively accomplishes the same thing as the work around I implemented. Pratik's solution might be better than what I eventually landed on, but I need to have a closer look at how the two compare.
The following DAX will give you a table with all buildings mapped against all rows in the period table, eliminating the requirement of a relationship.
SiteToPeriod =
CROSSJOIN(
SELECTCOLUMNS(Sites1, "Building name/label", Sites1[Building name/label]),
Period
)

Why is RankX always returning a 1?

I am using the AdventureWorks2016 data warehouse database. I created a measure named 'Total Sales Rank', which can be seen below. I am simply trying to rank each product according to sales (internet sales). The 'Total Sales' column in the table below is a measure (Sum([SalesAmount])) which sums all sales. I cannot figure out why RankX is returning 1 for each product. There are no filters in place. All the tables are properly related.
By the way, there are other questions somewhat like this but different enough where the answers do not help this situation.
You need to use ALL('Product') instead of just 'Product'.
Since you have products as filters (yes, you do!), for each row in your report RANKX "sees" only one record (for the product of the row). That's why you are getting "1"s. Instead, in each record you need to "see" the entire table, so that RANKX can compare multiple rows. This is accomplished by using ALL() function (or ALLSELECTED, etc).
This article might help you further:
Using RANKX

Measure to sum another aggregated measure's data

I am working on a report that has data by month. I have created a measure that will calculate a cost per unit which divides the sum of dollars by the sum of production volume for the selected month(s):
Wtd Avg = SUM('GLData - Excel'[Amount])/SUM('GLData - Excel'[Production])
This works well and gives me the weighted average that I need per report category regardless of if I have one or multiple months selected. This actual and budget data is displayed below:
If you take time to total the actual costs you get $3.180. Where I am running into trouble is a measure to sum up to that total for a visual (This visual does not total sadly). Basically I need to sum the aggregated values that we see above. If I use the Wtd Avg measure I get the average for the total data set, or .53. I have attempted another measure, but am not coming up with the correct answer:
Total Per Unit Cost = sumX('GLData - Excel','GLData - Excel'[Wtd Avg])/DISTINCTCOUNT('GLData - Excel'[Date])
We see here I return $3.186. It is close, but it is not aggregating the right way to get exactly the $3.180:
My Total Per Unit Cost formula is off. Really I am simply interested in a measure to sum the post aggregated Wtd Avg measure we see in the first graph and total to $3.180 in this example.
Here is my data table:
As you probably know already, this is happening because measures are dynamic - if you are not grouping by a dimension, they will compute based on the overall table. What you want to do is to force a grouping on your categories, and then compute the sum of the measure for each category.
There are 2 ways to do this. One way is to create a new table in Power BI (Modeling tab -> New Table), and then use a SUMMARIZE() calculation similar to this one to define that table:
SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg])
Unfortunately I do not know your exact column names, so you will need to adjust this calculation to your context. Once your new table is created, you can use the values from that table to create your aggregate visual - in order to get the slicers to work, you may need to join this new table to your original table through the "Manage Relationships" option.
The second way to do this is via the same calculation, but without having to create a new table. This may be less of a hassle. Create a measure like this:
SUMX(SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg]),[Wtd Avg])
If this does not solve your issue, go ahead and show me a screenshot of your table and I may be able to help further.