The number I see in the grand total is different from the sum of the rows (for previous year column [Önceki Yıl IPP]).
Table columns
Measures:
IPP Ciro:=SUM([Amount_])/1000
This measure calculates sum of revenue(Amount_)
Önceki Yıl IPP:=
VAR LastDaySelectionIPP =
LASTNONBLANK ( Tarih[Tarih], [IPP Ciro] )
VAR CurrentRangeIPP =
DATESBETWEEN ( Tarih[Tarih], MIN ( Tarih[Tarih] ), LastDaySelectionIPP )
VAR PreviousRange =
SAMEPERIODLASTYEAR ( CurrentRangeIPP )
RETURN
IF (
LastDaySelectionIPP >= MIN ( Tarih[Tarih] ),
CALCULATE ( [IPP Ciro], PreviousRange )
)
This measure calculates sum of previous year revenue.
I want to compare the current year with the last year same period.
Why is the Grand total is 98.998 for previous year[Önceki Yıl IPP]?
Grand Total is incorrect is SSAS Tabular Model
It’s not jumping out at me, but here’s how to debug it.
Add a new measure like this and add it to your table:
Debug:=
VAR LastDaySelectionIPP =
LASTNONBLANK ( Tarih[Tarih], [IPP Ciro] )
VAR MinDate = MIN ( Tarih[Tarih] )
VAR CurrentRangeIPP =
DATESBETWEEN ( Tarih[Tarih], MIN ( Tarih[Tarih] ), LastDaySelectionIPP )
VAR PreviousRange =
SAMEPERIODLASTYEAR ( CurrentRangeIPP )
VAR WrongAnswer =
IF (
LastDaySelectionIPP >= MIN ( Tarih[Tarih] ),
CALCULATE ( [IPP Ciro], PreviousRange )
)
RETURN LastDaySelectionIPP & “,” & MinDate & “,” & [IPP Ciro] & “,” & WrongAnswer
It will list the values you are using in the calculation and I predict you’ll find the unexpected value. Update us on what you find!
Related
I want count two columns using power bi to create a visual.my measure as below
Test Measure = COUNTA('Export'[Line])+COUNTA('Export'[Line 2]),
You need to create a calculated table with all the lines values, like this
TableValues =
DISTINCT ( UNION ( DISTINCT ( 'Table'[Line] ), DISTINCT ( 'Table'[Line_2] ) ) )
With that table done, you can write the following measure
CountValues =
VAR _CurrentValue =
SELECTEDVALUE ( TableValues[Line] )
VAR _C1 =
CALCULATE ( COUNTA ( 'Table'[Line] ), 'Table'[Line] = _CurrentValue )
VAR _C2 =
CALCULATE ( COUNTA ( 'Table'[Line_2] ), 'Table'[Line_2] = _CurrentValue )
RETURN
_C1 + _C2
The calculations count all the instances of a specific Line. It's important that the TableValues doesn't have any relationship with the other tables.
Output
Using 'TableValues'[Line] as the Line and CountValues as the metric.
I have a below matrix. I want to calculate the % Growth over month and to show in a matrix
Fields
Expected Output
Company
August
September
GOLM %
Total
EBS-EASEBUSINESS SOLUTIONS
5940
0
-100%
5940
SWEETREAT CAFE
5940
0
-100%
5940
M/S SPORTS ONE PHARMACY
1188
-100%
1188
Tried Solution
I have tried this Solution. But it's not working for me
GOLM =
VAR SelectedMonth =
SELECTEDVALUE (
Dates[Month],
MONTH ( TODAY () )
)
VAR PrevMonth =
SELECTEDVALUE (
'Source Data'[Month Updates],
MONTH ( TODAY () )
) - 1
VAR Growth =
CALCULATE(
DIVIDE(
SelectedMonth - PrevMonth,
PrevMonth,
0
)
)
RETURN
IF(
SELECTEDVALUE('Source Data'[Month Updates]) = PrevMonth,
SUM('Source Data'[SALES VALUE]),
IF(
SELECTEDVALUE('Source Data'[Month Updates]) = SelectedMonth,
SUM('Source Data'[SALES VALUE]),
FORMAT(Growth, "Percent")
)
)
Error
DAX File
Here is my Dax File
Maybe you can do something like this;
First create a DAX table by using modelling pane;
Growth =
VAR CurrentMonth = FORMAT(TODAY(), "MMMM")
VAR PrevMonth = FORMAT(EOMONTH(TODAY(),-1), "MMMM")
VAR tmp1 = SELECTCOLUMNS('Source Data',
"SV_PrevMonth", CALCULATE(
SUM('Source Data'[SALES VALUE]),
'Source Data'[Month Updates]=PrevMonth),
"SV_CurrentMonth", CALCULATE(
SUM('Source Data'[SALES VALUE]),
'Source Data'[Month Updates]=CurrentMonth),
"PN", 'Source Data'[ProductNameFull],
"CN", 'Source Data'[CustomerNameFull],
"CP", 'Source Data'[Company]
)
return tmp1
Then add a measure to your table
GrowthPercentage = CALCULATE(DIVIDE(SUM(Growth[SV_CurrentMonth]) - SUM(Growth[SV_PrevMonth]), SUM(Growth[SV_PrevMonth]),0))*100
The result wil be like;
You should be able to add a measure in the Source Data Table itself like below:
GLM =
VAR Curr_Month =
CALCULATE (
SUM ( 'Source Data'[SALES VALUE] ),
'Source Data'[Month Updates] = FORMAT ( EOMONTH ( TODAY (), 0 ), "mmmm" )
)
VAR Prev_Month =
CALCULATE (
SUM ( 'Source Data'[SALES VALUE] ),
'Source Data'[Month Updates] = FORMAT ( EOMONTH ( TODAY (), -1 ), "mmmm" )
)
VAR GROWTH = ( Curr_Month - Prev_Month ) / Prev_Month
RETURN
GROWTH
and of course, you need to change the format of the measure to PERCENTAGE.
Is this what you're looking for?
Follow Up :
I have these two tables that are mutually exclusive (not connected in any way) .
The first table has date , number of customers on the dayDISTINCTCOUNT(sales[user_name]), total sales , tier (text - will explain)
The second table is CustomerLimit which is basically consecutive numbers between 1 and 100.
Used the tier measure as the answer below (thank you)
Tier =
VAR Limit = SELECTEDVALUE ( CustomerLimit[CustomerLimit] )
VAR CustCount = COUNT ( Customers[CustomerID] )
RETURN
IF (
ISBLANK ( Limit ), "Select a value",
IF ( CustCount > Limit, "Good", "Bad" )
)
Now I need to aggregate the total amount of customers by Tier.
I used
calculate(DISTINCTCOUNT(sales[user_name]),Tier = "Good") .
It give me an error of : A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
Is that possible ?
You can capture the limit using SELECTEDVALUE and then compare.
Tier =
VAR Limit = SELECTEDVALUE ( CustomerLimit[CustomerLimit] )
VAR CustCount = COUNT ( Customers[CustomerID] )
RETURN
IF (
ISBLANK ( Limit ), "Select a value",
IF ( CustCount > Limit, "Good", "Bad" )
)
I can't find the right results for Closing Inventory, given the scenario below:
Measure added to Matrix Table:
Calculation=
VAR minDate =
CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
VAR curDate =
SELECTEDVALUE ( 'Calendar'[Date] )
RETURN
SWITCH (
SELECTEDVALUE ( HelperTable[ID] ),
1, IF ( curDate = minDate, [OpenInventoryMeasure], BLANK () ),
2, IF ( curDate > minDate, [ProdMeasure], BLANK () ),
3, [QtySalesMeasure],
4, if (curDate > minDate,[Closing Inventory], BLANK())
)
Here are the measures created and used in the main calculation above:
OpenInventoryMeasure =
VAR minDate =
CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
VAR curDate =
SELECTEDVALUE ( 'Calendar'[Date] )
return
CALCULATE(Sum('Production'[Qty]),FILTER('Calendar','Calendar'[Date] = minDate))
ProdMeasure =
VAR minDate =
CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
VAR curDate =
SELECTEDVALUE ( 'Calendar'[Date] )
return
CALCULATE(Sum('Production'[Value]),FILTER('Calendar','Calendar'[Date] > minDate))
QtySalesMeasure = SUM(PedItens[QTDUND])
ClosingMeasure = [OpenInventoryMeasure ] + [ProdMeasure] - [QtySalesMeasure]
Main issue: Right now, Closing measure is not giving me the right result, although the measure that make it up are correct.
Tiny issue: Also, the order is not right in the table, although I had ordered it by ID.
Here's a screenshot of the resulting table:
I appreciate any help.
The problem is with the Opening Inventory measure, because when you do the CALCULATE you are now on the context of the Monday, so it's already filtered by Monday and then you're adding an additional filter of date = 7th which returns blank.
You need to clear the filters first and then apply the date filter:
OpenInventoryMeasure =
VAR minDate =
CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
return
CALCULATE(Sum('Production'[Qty]), ALLSELECTED('Calendar'), 'Calendar'[Date] = minDate)
Your Prod measure probably suffers from the same error, but I don't understand what's the logic behind it because you only filter based on min date and not on current date.
I have a tabular data model in Visual Studio, I made a formula to get last year's sales over a given period:
Selected Measure LY:= CALCULATE([Selected Measure], SAMEPERIODLASTYEAR('date' [date]))
I made a formula to have the decomposition of all the months in the 'date' table:
FY_Month='date' [FY Month No]&'date' [Month_label]
And:
FY_Month_No=format(if('date'[month_no]>6,'date'[month_no]-6,'date'[month_no]+6), "00")
Month_label : all the months of the year
The "Selected Measure LY" display works fine when I have all months selected but when I remove one I get this error message:
Calculation error in "Selected Measure LY": the "SAMEPERIODLASTYEAR" function expects a contiguous selection when the date column comes from a tabkle on side 1 of a bidirectional relationship.
Between my 'date' table and my sales table I have a 1/N relationship, I tried to change this relationship too but the error always comes back.
I looked for solutions on forums and I found this but I don't find the same numbers as with my first formula:
Selected Measure LY:=
CALCULATE([Selected Measure],
FILTER (
ALL ( 'date' ),
YEAR ( 'date'[date] ) = YEAR ( TODAY () )
&& 'date'[date] <= TODAY ()
)
)
My code for Selected Measure:
Selected Measure:=
VAR hasFilter =
HASONEFILTER ( 'Measure Selection'[Measure Name] )
VAR selMeas =
SELECTEDVALUE ( 'Measure Selection'[Measure Name], BLANK () ) /*SWITCH works slow, so using many IFs*/
VAR preCalc =
IF (
selMeas = "Units",
[Sku Piece Quantity],
IF (
selMeas = "Net Sales",
[Euro Net Amount],
IF (
selMeas = "Gross Sales",
[Euro Gross Amount],
IF (
selMeas = "Average Wholesale",
[Average_Wholesale],
IF (
selMeas = "Average Units",
[Average Units],
IF (
selMeas = "No of Styles",
[Style Count],
IF (
selMeas = "No of Colours",
[Colour Count],
IF (
selMeas = "ROD by Style",
[ROD by Style],
IF (
selMeas = "Standard Cost",
[Sum_Cost_Base],
IF (
selMeas = "Net Margin",
[Net_Margin],
IF (
selMeas = "Gross Margin",
[Gross_Margin],
IF ( selMeas = "ROD by Colour", [ROD by Colour], BLANK () )
)
)
)
)
)
)
)
)
)
)
)
VAR calc =
IF ( hasFilter, preCalc, BLANK () )
RETURN
calc
How can I correct it?