EXCEL Sumifs to PowerBI - excel

I have a formula in Excel that gives me the sum of several cells if two conditions are met.
In Excel, the base has been converted into a table so that this works.
The formula is as follows:
=sumifs(B:B,B:B,">0",A:A,"<="&[# month])
In A I have sales and in B the month. If I have sales in A that are greater than 0, it should add up all sales for the months if the month of the line is less than or equal to the own month.
In Power BI, it only sums up all months from start to finish if the value is greater than 0, but not the amount of sales for the one month.
month
sales
sumifs
1
500
737
1
237
737
2
420
1157
3
380
1537
4
410
2437
4
280
2437
4
210
2437
5
0
2437

just create a new measure (or calculated column).
Sumif = SUMX('Tablename','Tablename'[sales])

try this:
Measure 2 = CALCULATE( sum(Table[sales]), FILTER(ALL(Table), Table[month] <= SELECTEDVALUE(Table[month])))

If you want to have the result as a separate column, you can do it with two queries:
Load_Data
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content]
in
Source
Calc_Sum
Group by month and sum up sales to get result per month
Add original data via month and show sales column to re-include the original sales
Rearrange the columns in case the order is relevant for you
let
Source = Load_Data,
Group = Table.Group(Source, {"month"}, {{"Sum_of_sales", each List.Sum([sales]), type nullable number}}),
AddOriginalData = Table.NestedJoin(Group, {"month"}, Load_Data, {"month"}, "Load_Data", JoinKind.RightOuter),
ShowSales = Table.ExpandTableColumn(AddOriginalData, "Load_Data", {"sales"}, {"sales"}),
Rearrange = Table.ReorderColumns(ShowSales,{"month", "sales", "Sum_of_sales"})
in
Rearrange

Try this Dax in a Calculated Column. It worked for me with your Data
SUMIF = CALCULATE(
SUM(Table[Sales]),
FILTER(ALL(Table), Table[Month] <= EARLIER((Table[Month]))),
Table[Sales] > 0
)
Do let me know if it worked for you.
Have a good day !!
Best Regards,
Pratik

Related

Excel formula to find Max and return a column from the matching row

My data looks some thing like this:
Product 1
Date
Site1_Sales
Site2_Sales
Site2_Sales
x1
1-Jan
100
200
300
x2
2-Jan
60
51
150
X1
2- Jan
110
30
40
There will be 1000s of rows with repeated Product but with unique dates. This is what I would like to find:
What was the Max sales for a product ? and on which date ? I tried using Maxifs but it ends up with value error it looks it can handle only continuous ranges.
What was the sum of sales for a product for specific period e.g first 10 days ?
Any help is really appreciated. Thank you
see “Remarks” about #value error:
https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883
SUMIF works in the same way as MAXIF (e.g. you could use a start date and end date as multiple criteria)
FILTER should help you to find the date(s) of max. Sales as well

DAX - referencing row header in a formula

I need your help in creating a DAX measure that would help me resolving the following problem:
I have a table that shows case number, creation date and closure date:
case_number creation_date closure_date
CA001 4/15/2020 4/19/2020
CA002 4/17/2020 4/20/2020
CA003 4/19/2020 4/21/2020
CA004 4/19/2020 4/20/2020
I have a pivot with various measures where row headers are consecutive days from a related Calendar table. One of the columns I need is a number of active cases in given day (number of cases that were created before or the same day as the context date, AND closed after the context date). The expected outcome would be like this:
date open_cases
4/13/2020 0
4/14/2020 0
4/15/2020 1
4/16/2020 1
4/17/2020 2
4/18/2020 2
4/19/2020 3
4/20/2020 1
4/21/2020 0
in regular Excel, the formula that calculates the same would be =COUNTIFS(table_cases[creation_date],"<="&[#date],table_cases[closure_date],">"&[#date]), but in my case this will be a part of a bigger pivot table/dashboard and I need to write a measure in DAX that would calculate this.
I would appreciate your help in this matter.
Best regards,
Michal
There are a variety of ways to read the current context. You can use MAX or VALUES or SELECTEDVALUE (if available). These don't all behave exactly the same, so use whichever is appropriate for your situation.
open_cases =
VAR RowDate = MAX ( Calendar[date] )
RETURN
CALCULATE (
COUNT ( table_cases[case_number] ),
table_cases[creation_date] <= RowDate,
table_cases[closure_date] > RowDate
)
Here, MAX is evaluated within the filter context, so it should return the value in the current row (or the maximal date for subtotals and grand totals).

Cuberankedmember getting wrong order

I'm trying to create a top3 ranking from a data table varying metrics but each time I get the wrong order from the cuberankedmember, usually misplacing ranks 2 and 3.
The data I'm mostly focused on is regarding sales revenue. Power pivot sums all sales by store, quite straight forward.
From this I use a cubeset formula that captures store name, filtered by a month and year, which the user types in as any day for the month, and set the measure which to sort by (NTS) (code 1).
The cuberankedmember selects the cubeset and defines the position (code 2).
Then the cubevalue selects as members the cuberankedmember, filters once again month and year, then pulls in the measure (code 3).
E4 is the date
Code1 (cell C21):
=CUBESET("ThisWorkbookDataModel";
"NONEMPTY([Store_Dict].[Nome_DSR].children,
([Calendar].[Year].[All].["&YEAR($E$4)&"],
[Calendar].[Month Number].[All].["&MONTH($E$4)&"]))";
"Ranking";
2;
"[Measures].[NTS]")`
`Code2` (cell `D22`):
`=CUBERANKEDMEMBER("ThisWorkbookDataModel";$C$21;1;"a")
`C21` is the `CUBESET` formula
Code3:
CUBEVALUE("ThisWorkbookDataModel";
$D22;
"[Calendar].[Month Number].["&MONTH($E$4)&"]";
"[Calendar].[Year].["&YEAR($E$4)&"]";
"[Measures].[NTS]")
Actual Result:
Ranking Store NTS
1 a 606
2 c 425
3 b 428
Expected result:
Ranking Store NTS
1 a 606
2 b 428
3 c 425

PowerPivot Grand Total, Sum of all change in %s?

So I am working on a report that has to show total 'pts' in a table based on the performance of certain groups of work.
Right now I have a PowerPivot that Sums Actuals, Forecasts, and the Variance. Then I have separate formulas that filter on each group so that I get a variance % based on each group.
Example formula - 'Group1 Acc:=ABS(CALCULATE(([Actual]-[Forecast])/[Actual],talbe[name]="Group 1"))'
I want the table to look like this....
Column Group 1 Group 2
Criteria 1 25% 25%
Criteria 3 20% 20%
Criteria 4 10% 10%
Grand Total 21.2% 55%
Group 1 is how it is currently working and makes sense to me but isn't doing what I want. It is getting the weighted % change of all the groups. Total Actual-Total Forecast/Total Forecast basically. In this example it comes out to 21.2% because Criteria 4 had a larger % of the total Actual and Forecast for the time period I am comparing.
I want it to work like it is showing in Group 2. The SUM of the total %s over each criteria group. I've tried SUMX formulas, Value(), and such but can't figure this out. Any help would be appreciated.
Thank you!
Check out this article: Subtotals and Grand Totals That Add Up “Correctly”
Basically, you can create logic so that the total behaves separately from the individual rows. Something along these lines:
Measure =
IF(COUNTROWS(VALUES(Table1[Criteria])) = 1,
[Group 1 Acc],
SUMX(VALUES(Table1[Criteria]), [Group 1 Acc])
)
Data:
Type Actual Forcast
Criteria1 33 32
Criteria2 543 345
Criteria3 643 633
Criteria4 45 65
Criteria5 7890 7999
MEASURE 'datatable'[SumOfActuals] =
SUM ( 'DataTable'[Actual] )
MEASURE 'datatable'[SumOfForcast] =
SUM ( 'DataTable'[Forcast] )
MEASURE 'datatable'[Group1] =
DIVIDE (
'datatable'[SumOfActuals],
CALCULATE ( 'datatable'[SumOfForcast], ALLSELECTED () )
In Excel, filter for Criteria 3 and 4
Row Labels Group1
Criteria3 92.12 %
Criteria4 6.45 %
Grand Total 98.57 %

DAX - Distinct SUM thru 2 dimensions

I am trying to calculate "Distinct Sum" in DAX Powerpivot. I already have found help here: http://stackoverflow.com/questions/22613333/dynamic-sum-in-dax-picking-distinct-values
And my query is similar but extended further. I am seeking to find solution for such distinct Sum, but via two additional dimension (Month + Country)
In data example below there is Revenue performance on Part Number granularity. in Data there is also Shop Dimension, however Revenue is repeating on shops, is duplicated.
In the post mentioned above there is following solution:
Support:=MAX(Table1[Revenue])
DistinctSumOfRev:=SUMX(DISTINCT(Table1[Part_Num]),[Support])
It is work perfectly if you use Filter/Column/Row: Country and Month.
But if aggregate for All countries, or show performance on whole quarter, then solution will set MAX Revenue thru all countries/Months for and Part Number, which is not correct.
How to include into above solution also those two additional dimensions.
Basically to tell DAX that unique combination is PartNum+Country+Month
Country Month Part_Num Shop Revenue
----------------------------------------
UK 1 ABCD X 1000
France 1 ABCD X 500
France 1 ABCD Y 500
UK 2 ABCD X 1500
UK 2 ABCD Y 1500
UK 1 FGHJ X 3000
France 1 FGHJ X 600
UK 2 FGHJ X 2000
Add a calculated column to your Table1:
PartNumCountryMonth = [Part_Num]&[Country]&[Month]
Then create your measure as follows:
DistinctSumOfRev:=SUMX(DISTINCT(Table1[PartNumCountryMonth]),[Support])
Update
Alternative solution, calculated column is NOT required:
DistinctSumOfRev :=
SUMX ( SUMMARIZE ( 'Table1', [Country], [Part_Num], [Month] ), [Support] )

Resources