Power Bi creating monthly measure from repeated monhts - sql

I have an application database that is designed the following way: (I cannot change it)
I need to be able to create a cash flow that can tell me by month, Property and type what the amount of that month is. I figured I need in a measure in a table that has all the months I need, but I am not sure how to do it.
Any help would be greatly appreciated it!
Link to screenshot, it wont let me post it directly

Even with the screenshot, it is not entirely clear to me what is meant by repeated month. I am assuming that if repeat_count = 2 and amount = 100 then amount_wanted = 200.
I am also assuming that you already loaded the data into Power BI.
In that case you need to perform the following steps:
Create a calculated column holding the month. You can do so using the function month(date).
Create a calculated column as
amount_wanted = [repeat_count] * [amount]
Create a new measure:
new_measure = sum([amount_wanted])
Create a matrix visual with property and type in the rows, month in the columns and new_measure in the values.

Related

Power BI: Measure for Date difference depending on other columns

I hope everybody is doing fine! :)
I have a table like the one in my "Example" picture. Let's say it is data about certain products and a certain assembly status (i.e. column "Status"). In "Status Date" I can see the date on which the product has been in the specific status. I only added dates for ID 1 to make the table easier.
Table
What I am looking for is a measure in Power BI to calculate the difference (in days or month doesn't matter) between the dates. I don't want to use the number in the Status (e.g. 1 for Stat 1) to identify the order of the dates. To make it even harder, I may want to filter out Stat 2 for some reason. In that case I want the measure to automatically adapt and calculate the difference between Stat 3 and Stat 1.
I have the feeling that this is possible in a single formular using a measure which would be the optimal solution from my point of view.
I hope there's someone who can help me!
Thanks in advance.
Daniel

Is there any ways to dynamic cumulative measure in MDX?

All of the measure that I want to cumulative has the same formula. So, is there any way to use the thing like function or any thing in calculate measure to resolve this issue?
There are two ways to achieve your aim:
1- the first solution is based on using the business intelligence wizard to add time intelligence to your solution.
The time intelligence enhancement is a cube enhancement that adds time calculations (or time views) to a selected hierarchy. This enhancement supports the following categories of calculations:
List item
Period to date.
Period over period growth.
Moving averages.
Parallel period comparisons.
The wizard will let you chose the calculations and measures you want to apply.
Visit : https://learn.microsoft.com/en-us/analysis-services/multidimensional-models/define-time-intelligence-calculations-using-the-business-intelligence-wizard
Visit : http://www.ssas-info.com/analysis-services-articles/62-design/2465-ssas-time-intelligence-wizard
2- Use a dimension table to calculate your calculations, this solution is more complicated, but very powerful and one of the best practices.
The first step is to create a new physical dimension, with real
members for each of the calculations we're going to need. We don't
actually need to create a table in our data warehouse for this
purpose, we can do this with an SQL view like this
CREATE VIEW DateTool AS SELECT ID_Calc = 1, Calc = 'Real Value' UNION ALL SELECT ID_Calc = 2, Calc = 'Year To Date'
Next, we need to add this view to our DSV and create a dimension based
on it. The dimension must have one hierarchy and this hierarchy must
have its IsAggregatable property set to False. The DefaultMember
property of this hierarchy should then be set to the Real Value
member. Giving this dimension a name can be quite difficult, as it
should be something that helps the users understand what it does –
here we've called it Date Tool. It needs no relationship to any
measure group at all to work.
Our next task is to overwrite the value returned by each member so
that they return the calculations we want. We can do this using a
simple SCOPE statement in the MDX Script of the cube:
this code let you create the YEAR-TO-DATE aggregation for all your measures.
SCOPE ([Date Tool].[Calculation].[Year To Date]); THIS = AGGREGATE ( YTD ([Date Order].[Calendar].CurrentMember), [Date Tool].[Calculation].[Real Value]); END SCOPE;
Visit:https://subscription.packtpub.com/book/big_data_and_business_intelligence/9781849689908/6/ch06lvl1sec35/calculation-dimensions

Trying to SUM a formula field based on constraints from another field

A little background on the report:
This is a productivity report for our employees working at our business. We determine their productivity based on the duration of the visits with clients. Some of our employees offer group sessions. They charge each client within the group, even though they are only giving, for example, one hour of service, they can bill for 10 hours if there are 10 people in the group. We determine what service they gave by service codes.
So, I have two fields in this formula, a service code field and a duration field.
The duration field is initially a STRING field from the database, even though it only gives number data, so I change it to a numberVar. The service code field is also a string field, and it sometimes does contain characters and numbers.
What I need Crystal Reports to do is take the sum of the duration. However, if the service code is, say, "1000", it must first divide the duration by 3 before summing it. This is where I get caught up.
Here's my code for the duration:
local numbervar num1;
If GroupName ({billing_tx_charge_detail.v_SERVICE_CODE})="1530" then
num1 := ToNumber({billing_tx_charge_detail.v_duration})/3
else num1 := ToNumber({billing_tx_charge_detail.v_duration})
Then I do a separate formula for the sum, named sumDuration:
Sum(#duration)
I get the error that this field cannot be summarized. After searching Google for two days I have found that Crystal cannot summarize fields or formulas involving constants. If I simply say:
local numbervar num1;
num1 := ToNumber({billing_tx_charge_detail.v_duration})
then I can summarize #duration. What am I missing? It has to be something simple, but I'm just not seeing it. Is there a way to create a custom function to accomplish what I am trying to get here? Or is it even simpler than that?
One person suggested creating a SQL command in order to do the calculations before the data gets to the report. I am a SQL newb so I had no idea where to even begin with that.
If you are grouping by Service Code and placing the above formula in the footer you will only be computing {billing_tx_charge_detail.v_duration} for the last record in the group. If you are intending to use the formula and sum the results and place the results in the Service Code footer try the following. (basically remove the reference to group name)
If {billing_tx_charge_detail.v_SERVICE_CODE}) = "1530" then
ToNumber({billing_tx_charge_detail.v_duration})/3 else
ToNumber({billing_tx_charge_detail.v_duration})
You can use variables (num1) if you want to but they are not needed.
You can still use the second formula you referred to and place in the group footer OR you can place the first formula in details section, right click and insert a summary to the group footer. You can also place in the report footer if you need it to total there as well.

Specific info on access report

Probably get shot for posting this again but last attempt was put on hold so sorry in advance. i am very new at this so apologies if its a simple answer;
I created a table with name of purchaser, items purchased, date of purchase and cost of purchase. From that i wanted to create a report that would show each purchasers name only once with a combined total cost of all purchases.
I created a query that did just that using only the purchasers name and the total cost of their purchases. I then created the report from that query.
The report shows each name once with a total cost of purchases which was great except for the query continually adds those total purchases without the ability to select a date range and likewise the report shows the same info.
When i add the purchased date to the query/report so i can filter between 2 date ranges it then shows each name "X" amount of times with a total for each purchase made which is not what i am looking for as this ends up with a long report.
Hope this makes more sense than my last attempt at this question. I am very new at this so a simple answer would be great.
Thanks in advance
You need to get two parameters for the query, say [Start] and [End].
You need to add the date column twice so that it can be compared to [Start] AND [End]
You need to add the date column (on both occasions) with a Total "Where"; this tells access that the column has no other purpose than to impact a WHERE-constraint on the base dataset.
If you run into trouble, take the SQL below, correct all names in it, paste it into the query's SQL view, and then see what the design view looks like!
SELECT table.customer, Sum(table.price) AS sum
FROM table
WHERE (((table.date)>=[Start]) AND ((table.date)<=[End]))
GROUP BY table.customer;

MDX Calculated Member SubCube

I am relatively new to this depth of MDX, but here is my dilemma. My goal is to implement a calculated member using a .Net Stored Procedure. The calculation (XIRR) will be based on a set of cash flow dates and cash flow amounts. Ideally this would be a calculation in my cube that is available as a measure to Excel/Browser users.
So to start simple I am just trying to implement my own COUNT calculated member/measure (not even using .Net) to say count the # of members in a given dimensions based on the current context. So lets say I have a dimensions Customer with a Customer Id Key. And let's say there are a total of 100 customers in my database. So Count(Customer.CustomerId.AllMembers) would be 100. Now when you start using the browser and say filter on Customer.CustomerId.&1, Customer.CustomerId.&2 (customer id 1 and 2) I would expect my count calculated member to return 2 but it returns the total 100 count. I have tried using exists. I am sure there is something that I am just fundamentally not understanding yet.
Hopefully this makes sense, would hugely appreciate any help from someone that has a good understanding of SSAS/MDX and calculations. Thanks in advance.
Marty
You may have some issues here, I did when I tried to do a similar thing.
Your calculated member is not honouring the client sub-select, which is normal. What in theory you would do is create a dynamic set, and then use that in the calculated member to force the dimension count to be evaluated in the context of the subcube your filters have created. Mosha has a good article here: http://sqlblog.com/blogs/mosha/archive/2007/08/25/mdx-in-katmai-dynamic-named-sets.aspx
So you'd end up with something like:
CREATE DYNAMIC SET CurrentCube.Customers AS
EXISTING(Customer.CustomerId.CHILDREN);
CREATE MEMBER CurrentCube.Measures.CustomerCount AS
Customers.COUNT
Now the real problem you'll have is a bug in SSAS https://connect.microsoft.com/SQLServer/feedback/details/484865/calcuated-member-with-a-reference-to-dynamic-named-set-kills-the-cubes-performance so the code above, which will probably work just fine locally, will kill a production cube. This was an exciting learning experience for me.
See if you can get any of the workarounds to work, I couldn't.
I was able to get what I wanted, but I had to create query-scoped dynamic sets as part of the MDX query, I wasn't able to create it as a cube object:
WITH DYNAMIC SET Customers AS
EXISTING(Customer.CustomerId.CHILDREN);
MEMBER Measures.CustomerCount AS
Customers.COUNT
SELECT
Measures.CustomerCount
ON COLUMNS
FROM [Cube]
WHERE Customer.CustomerId.&[1]
Let us know how you get on.