I am with the issue of difference between previous quarter, next quarter and current quarter. I have created date field and use the following calculation to resolve the issue but there is showing aggregated 4 quarters total instead of difference between last quarter and current quarter. The attached screenshot showing the grand total figure and quarter difference figure is same.
But the result is same. Only showing the total figure to sum all quarters. Please help me to find out the way to resolve the issue.
=IF (
FIRSTNONBLANK (
'10QuarterlyReportProgressPC'[Quarter], 1 ) = "Q1",
SUM ('10QuarterlyReportProgressPC'[Progress] ),
SUM( '10QuarterlyReportProgressPC'[Progress] )
- CALCULATE ( SUM ( '10QuarterlyReportProgressPC'[Progress]
),
PREVIOUSQUARTER ( '10QuarterlyReportProgressPC'[Start_QuarterYear] ) )
)
Related
I have 2 tables for stock management. 1 for the list of stock and some other properties and 1 for the daily values (i have a relationship between both on the index of the stock).
I would like to have a weekly performance ie the value has increased/decreased by xx from the previous week.
So I created a table (weeklies) with a few rows which correspond to a week for each row. I have 2 columns: 1 is the beginning date of the week, 1 is the last date of the week.
Im creating a calculated third column with the sum of all the values at the beginning date of a given week :
CALCULATE (
SUMX ( Daily_Stock; [Price] * RELATED ( Stock_list[Qty] ) );
FILTER ( Daily_Stock; Daily_Stock[Date] = weeklies[begin_date] )
)
It works fine but I would like to exclude some stocks which were sold before the beginning date (i have other reasons to be able to achieve this) so I'm trying to multiply by 0 if it is the case for that specific stock.
CALCULATE (
SUMX (
Daily_Stock;
[Price] * RELATED ( Stock_list[Qty] )
* IF ( RELATED ( Stock_list[sold_date] ) < weeklies[begin date]; 0; 1 )
);
FILTER ( Daily_Stock; Daily_Stock[Date] = weeklies[begin_date] )
)
There I have the following error :
A single value for column sold_date in table Stock_list cannot be determined.
Tweaking around a little bit and I had the same error on the weeklies table.
Does anyone know what I should be doing here?
I can explain more, I wanted to avoid a too-long post.
thanks
I think the issue is the relation.
I assume the RELATED is based on the stock index you mentioned.
I think related stock_list[sold_date] returns all dates that RELATED stockID has ever been sold.
Which would mean you are trying to compare more than one date with weeklies[begin date].
image copied from powerpivotpro on using VALUES with IF in measures.
If i am right, you need another way of relating to your stocklist to get singular matches. I am not sure if the VALUES solution rob collie uses for measures will work here, but maybe it is worth testing. Rob collie powerpivotpro - Magic of IF(VALUES)
I'm currently working on a PowerBI script, which gives me headaches. I introduced a measurement, which shows the amount of sales for every company in a corporation. Which basically looks like this.
MarketShare =
DIVIDE(
CALCULATE(
SUM('Monthly Reports'[Active Certificates])
),
CALCULATE(
SUM('Monthly Reports'[Active Certificates]),
ALL('Monthly Reports'[Institute])
)
)
The output of this is a beautiful matrix showing me the marketshare of every company compared to the total sales.
Now I should display in a matrix below, (or the same, even better) the change of market share for every company every month. Hence, July should display a blank cell since it has no data before. August should display in the first line +0,34 in September +0,3 ... etcetera for every entry in line one and continuing down.
I tried to implement a measure, which deducts always the values from the previous one, but I have not been successful so far.
Market Share Prev Period =
(
DIVIDE(
CALCULATE(
SUM('Monthly Reports'[Active Certificates])
),
CALCULATE(
SUM('Monthly Reports'[Active Certificates]),
ALL('Monthly Reports'[Institute])
)
)
)
-
(
DIVIDE(
CALCULATE(
SUM('Monthly Reports'[Active Certificates]),
DATEADD('Monthly Reports'[LoadDate], -1, MONTH)
),
CALCULATE(
SUM('Monthly Reports'[Active Certificates]),
DATEADD('Monthly Reports'[LoadDate], -1, MONTH),
ALL('Monthly Reports'[Institute])
)
)
)
I get weird results at the moment. If I choose to filter by date and add the entire date the following table is displayed, it shows the correct differences for the middle dates, however not for the final date:
When I filter by date hirarchy and months (like in the other table above) I get exactly the same results again.
Thanks,
Vincenz
In your calculation you use ALLEXCEPT.
ALLEXCEPT removes the filters from the expanded table specified in the first argument(remove from all column in this table), keeping only the filters in the columns specified in the following arguments. That means you keep context from your matrix (July from your header). conditions are mutually exclusive.
You want to do the opposite thing, remove the filter from your "date" column. Use ALL('TableName'[ColumnName])
Your first measure should looks like:
Simple =
DIVIDE(CALCULATE ( SUM ( 'Monthly Reports'[Sales] ) )
, CALCULATE (
SUM ( 'Monthly Reports'[Sales] ),
ALL ( 'Monthly Reports'[Company] )
))
I solved my calculation and found a workaround for the wrongly displayed date hierarchy.
Sometimes the answer to a question if you're not familiar with a programming language yet is simpler as one could expect.
Finished working code:
Market Share Prev Period =
IF(
CALCULATE(
SUM('Monthly Reports'[Sales]),
PREVIOUSMONTH('Monthly Reports'[SaleDate])
)
<> BLANK()
,
(
DIVIDE(
CALCULATE(
SUM('Monthly Reports'[Sales])
),
CALCULATE(
SUM('Monthly Reports'[Sales]),
ALL('Monthly Reports'[Company])
)
,
0
)
)
-
(
DIVIDE(
CALCULATE(
SUM('Monthly Reports'[Sales]),
PREVIOUSMONTH('Monthly Reports'[SaleDate])
),
CALCULATE(
SUM('Monthly Reports'[Sales]),
PREVIOUSMONTH('Monthly Reports'[SaleDate]),
ALL('Monthly Reports'[Company])
)
,
0
)
),
"-"
)
I figured out, that be using DateAdd(.., -1, Month) I only changed what was read, not in which column it goes. So I was always missing the most recent value, as off course it was not read by the -1 operation and I was missing the oldest report as there was none before off course.
Basically I found the function: PREVIOUSMONTH (too simple to be true).
Furthermore, I added an IF clause before to check if I'm at the first column. If so, I'm dashing the value.
My only problem, which was left in the end, was that when displaying the date hierarchy I only saw dashes in all the fields of the matrix. However, if I displayed the whole date I could see all correct values. My workaround was to format the date with "mmmm". This displayed the same. I hope I will not need the date in any further step, as I will need to come back to this again.
So my result looked exactly perfect.
I have a fact table with settlement_date, product_id, service_id, location_id, and ticket_id and srv_adjusted_earning columns.
I have determined the DAX query to generate a calculated column that sums the srv_adjusted_earning column over the date range: settlement date and settlement date - 27 days (i.e. a 4 week window) as:
=CALCULATE(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
FILTER(factService, factService[PRO_ID] = EARLIER(factService[PRO_ID])),
FILTER(factService, factService[SER_ID] = EARLIER(factService[SER_ID])),
FILTER(factService, factService[LOC_ID_SELLING] =
EARLIER(factService[LOC_ID_SELLING])),
FILTER(factService, factService[TIS_ID] = EARLIER(factService[TIS_ID]))
)
I am trying to convert this DAX calculated column to a measure and I tried the following:
blob:=CALCULATE
(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
ALLEXCEPT(factService, factService[PRO_ID]),
ALLEXCEPT(factService, factService[SER_ID]),
ALLEXCEPT(factService, factService[LOC_ID_SELLING]),
ALLEXCEPT(factService, factService[TIS_ID])
)
But I get:
Error: Calculation error in measure 'factService'[blob]: A single value for column 'SETTLEMENT_DATE' in table 'factService' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
Anybody know how I fix this?
As the error mentions, the issue is with factService[SETTLEMENT_DATE]. In the measure, there is no row context so that it knows which date you are talking about, so you need to specify it somehow. I'd suggest using a variable along these lines:
blob :=
VAR SettleDate = MAX ( factService[SETTLEMENT_DATE] )
RETURN
CALCULATE (
SUM ( factService[SRV_ADJUSTED_EARNING] ),
DATESBETWEEN (
factService[SETTLEMENT_DATE],
SettleDate - 27,
SettleDate
),
ALLEXCEPT (
factService,
factService[PRO_ID],
factService[SER_ID],
factService[LOC_ID_SELLING],
factService[TIS_ID]
)
)
Here the variable picks the maximal settlement date in the current filter context. If that's not exactly what you need, adjust the definition accordingly.
I'm working on Excel and Power Pivot and I'm trying to get the average sales between the last day of the past month and the last day of the current month, but I'm unable to get the right expression for it.
I have the "Credits" table and the "Calendar" table, both linked by the "Date" field.
So, this is what I have:
=CALCULATE ( AVERAGE(Credits[Sales] );
FILTER ( Calendar ;
Calendar[DateNum] >= VALUE(FORMAT(STARTOFMONTH(Calendar[Date])-1;"YYYYMMDD"))
&&
Calendar[DateNum] <= VALUE(FORMAT(ENDOFMONTH(Calendar[Date]);"YYYYMMDD"))))
I use that measure in a dynamic table along with the "Month" dimension, but it only shows the average for the full month, not taking into account the filters I'm trying to apply so that it also takes the last day from the previous month.
I think what's happening is that the month is still in your filter context.
Try FILTER( ALL(Calendar) ; instead.
I think you could probably also simplify your measure a bit. Maybe try something along these lines:
CALCULATE(
AVERAGE( Credits[Sales] );
DATESBETWEEN(
Calendar[Date];
STARTOFMONTH( Calendar[Date] ) - 1;
ENDOFMONTH( Calendar[Date] )
)
)
I have a data set as presented in the Sample 1 image below, and I need to generate a ratio of events per Serial Number (summary table as shown in the image).
The curve ball I got into here is the fact that the count of events ad sub events is monthly and the count of serial numbers is every 3 months, therefore the SN count needs to move the time period dynamically. In other words in March I need to divide the events from March by the count of SN's from January to March, while on April i need to divide the events from April by the count of SN's from February to April.
Any idea on how to do this?
Thanks in advance for all the help
You will have to create two calculated columns in your table to get the month number and the month from the distinct count should be calculated.
MonthNumber =
SWITCH(
[Event Month],"Jan",1,"Feb",2,"Mar",3,"Apr",4,"May",5,"Jun",6,
"Jul",7,"Ago",8,"Sep",9,"Oct",10,"Nov",11,"Dec",12)
MonthFrom =
SWITCH([Event Month],"Jan",1,"Feb",1,"Mar",1,"Apr",2,"May",3,"Jun",4,"Jul",5,"Ago",6,
"Sep",7,"Oct",8,"Nov",9,"Dec",10)
Then you can create this measure that will give the SN distinct count of the last three months:
SN Count =
CALCULATE (
DISTINCTCOUNT ( Event[SN] ),
FILTER (
ALL ( Event ),
Event[MonthNumber] >= MAX ( [MonthFrom] )
&& [MonthNumber] <= MAX ( [MonthNumber] )
)
)
Let me know if this helps.