How to do a SUMX on a GroupBy table in Webi? - powerbi

I have a DAX code in PowerBI that displays how many "check-ups" have been done in a particular location.
I am currently trying to transfer this over to SAP Web Intelligence Rich Client.
1.2_FrequenciedDay- =
var minDate=MIN(Datekey[ModifiedDate])
var maxDate=MAX(Datekey[ModifiedDate])
var summarizedTable=SUMMARIZE('x','x'[Datekey],"count",distinctcount('x'[DivisionKey]))
var Cumulativesum=SUMX(FILTER(summarizedTable,[Datekey]>=minDate&&[Datekey]<=maxDate),[count])
return Cumulativesum
Is there a SUMX and SUMMARIZE translations for Web Intelligence?

Related

Power BI Min date of each category

I am familiar with SQL and I can write a query to return results of a query to Select MIN(Date), MAX(Date), SUM(quality) and GROUP BY. However, I am new to Power BI and DAX and find it difficult to do the same on Power BI. Below is my situation.
These tables on Power BI:
Dim_ManefactureDate
Dim_ReleaseDate
Fact_OrderID
Table Relationships
Adding a table visualization to a new page to show data from three tables above, data is showing as below:
Under Values of Visualizations, when selecting SUM over Netweight, it automatically summarizes expected Netweight. However, for ManufactureDate and ReleaseDate, when selecting Earliest then Power BI table shows unexpected 1/01/1900 values like this:
I expect earliest date of each OrderID as below:
I have also tried to use a DAX function to create a new column but it gets error
ManufactureDate_Earliest =
VAR Sum_Netweight = SUM(Fact_OrderID[NetWeight])
VAR GroupBy_OrderID = GROUPBY(Fact_OrderID,Fact_OrderID[OrderID])
RETURN
CALCULATE(
MIN(RELATED(Dim_ManufactureDate[DateBK]))
)
Thank you very much for your help
Due to getting values from relationship tables, used these measured and solved the issue
ManufactureDate_Earliest =
CALCULATE(
MIN(ManufactureDate[DateBK]),
CROSSFILTER(Fact_Order[ManufactureDate_DateSK], ManufactureDate[DateSK], BOTH)
)
ReleaseDate_Earliest =
CALCULATE(
MIN(ReleaseDate[DateBK]),
CROSSFILTER(Fact_Order[ReleaseDate_DateSK], ReleaseDate[DateSK], BOTH)
)

PowerBI CALCULATETABLE, FILTER with SELECTEDVALUE

Am creating a table from original with filter condition, where my filter value is from SELECTEDVALUE
Table is not getting filtered on SELECTEDVALUE, if I replace with a real value then it works.
Code (doesn't work)
TransGt5 =
var seletectedQuanity = SELECTEDVALUE(QuantityFilter[Quantity])
return CALCULATETABLE(
Transactions,
FILTER(
ALL(Transactions),
Transactions[Quantity] >= seletectedQuanity
))
Code works file with hard coded value:
TransGt5 =
var seletectedQuanity = SELECTEDVALUE(QuantityFilter[Quantity])
return CALCULATETABLE(
Transactions,
FILTER(
ALL(Transactions),
Transactions[Quantity] >= 3
))
what am doing wrong?
That's not how Power BI works conceptually.
DAX can be used in 2 ways: to query data, and to define data (similar to SQL).
For queries, you can create DAX measures. They are executed in the run time and can respond to slicers and other user actions.
For calculated tables and columns, you can also write DAX code, but it's executed only in design time, when you create the code or refresh the data. It does not run as a query, and can not respond to user actions. The fact that you used DAX to create a table is irrelevant - the result is a static table, identical to the imported tables.
The only way to make it work is to build a measure. Inside measures, you can calculate tables, store them in variables, use them to calculate whatever you need and then publish a result. The result will be responsive to slicers.
For example, it could be something like:
Example =
VAR seletectedQuanity = SELECTEDVALUE ( QuantityFilter[Quantity] )
VAR FilteredTable =
CALCULATETABLE (
Transactions,
Transactions[Quantity] >= seletectedQuanity )
VAR Result = SUMX ( FilteredTable, Transactions[Quantity] )
RETURN Result
(although for this example, there are easier ways to achieve the same results, without the calculated table)

PowerBI DAX Filtering by MIN/MAX Date from Slicer

I have a table named 'Master Query' that holds a column called 'RegisterDate'. My PowerBI dashboard has Date Slicer that allows the user to control the data shown on a Matrix table. I am trying to create a new summarised table by filtering the MIN and MAX Date ranges that the user has chosen in the slicer.
I have tried this DAX code below but it seems the dates are not being picked up as all rows are returning rather than only summarising the rows within the desired date range:
HE KPI Card =
VAR _MinDate = CALCULATE(MIN('Master Query'[RegisterDate]),ALLSELECTED('Master Query'[RegisterDate]))
VAR _MaxDate = CALCULATE(MAX('Master Query'[RegisterDate]),ALLSELECTED('Master Query'[RegisterDate]))
RETURN
CALCULATETABLE(SUMMARIZE('Master Query',Students[ID],'KPItarget'[Description],"Mark1",SUM('Master Query'[Mark1]),"Mark2",SUM('Master Query'[Mark2]),"AuthCount",SUM('Master Query'[AuthorisedCount])),FILTER('Master Query','Master Query'[RegisterDate] >= _MinDate && 'Master Query'[RegisterDate] <= _MaxDate))
Main part of DAX code:
HE KPI Card =
VAR _MinDate = CALCULATE(MIN('Master Query'[RegisterDate]),ALLSELECTED('Master Query'[RegisterDate]))
VAR _MaxDate = CALCULATE(MAX('Master Query'[RegisterDate]),ALLSELECTED('Master Query'[RegisterDate]))
RETURN
FILTER('Master Query','Master Query'[RegisterDate] >= _MinDate && 'Master Query'[RegisterDate] <= _MaxDate))
How would I go about doing this? I am unsure why my DAX is not working...perhaps there is a better way of doing it within PowerBI
Calculated Table are "calculated" once at refresh time.
https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-calculated-tables
Calculated tables are recalculated if any of the tables they pull data
from are refreshed or updated, unless the table uses data from a table
that uses DirectQuery
If you want to only show summarized data then a better idea is to create new measures with 0/1 output. Put everything that you need to table visualization -> columns and measures + add to filter pane this new measure to show only 1 (based on your date condition).
If this is not the case, then describe in detail what do you want to achieve.

How is the Trend measure being calculated in the Power BI Usage Metrics reports?

The link https://learn.microsoft.com/en-us/power-bi/collaborate-share/service-modern-usage-metrics says "The view trend reflects view count changes over time. It compares the first half of the selected time period with the second half." but how would I do this with a measure?
View Trend measure is available in the dataset in modern workspace usage metric. However it is not available in the classic workspace usage metric or the old usage metrics report. This DAX is what I have written and have been using...
Trend =
VAR StartDate = MIN(Views[Date])
VAR EndDate = MAX(Views[Date])
VAR PeriodHalfDaysCount = INT((MAX(Views[Date])-MIN(Views[Date]))/2)
VAR MidDate = StartDate+PeriodHalfDaysCount
VAR FirstHalfView = CALCULATE([ViewsCount], DATESBETWEEN(Views[Date],StartDate,MidDate))
VAR SecondHalfView = CALCULATE([ViewsCount], `enter code here`DATESBETWEEN(Views[Date],MidDate+1,Enddate))
RETURN DIVIDE (SecondHalfView-FirstHalfView,FirstHalfView)

Power BI Rank within Matrix Visual

I've spent many weeks trying to get this to work including a posting at another site. No luck. Not sure what I'm missing.
The following code gets me the table of data that I need. However, I want just the "rank" value and I want it for each row within a matrix visual.
First some background, the PowerBI page has slicers on dates and "base" product. Any given product may be sold in multiple countries. All carry the same base product suffix with a country-specific prefix.
The matrix in question displays several aspects of all the product variants for the selected base product. I want to show where each variant ranks (unit sales) within its country.
VAR tblCountrySales =
SUMMARIZE (
FILTER(
tblSalesUnits,
RELATED(tblProducts[Country])="US"
),
tblProducts[ProdID],
"Total Sales", SUM ( tblSalesUnits[Units] )
)
RETURN
ADDCOLUMNS (
tblCountrySales,
"ProductRank", RANKX ( tblCountrySales, [Total Sales] )
)
Is there a way to either pull just the rank for a single product from the above code, or, better yet, a DAX pattern that will get me the rank by unit sales of each product variant within its respective country?
I've use these statements to successfully get the product ID and country for each row within the visual.
VAR ProdSales = SUM(tblSales[Units])
VAR ProdCountry = SELECTEDVALUE(tblProducts[Country])
Any help is greatly appreciated. I assume I'm missing something with row context within the visual as a simple COUNTROWS on the table expressions above always returns "1". Being new to PowerBI and DAX I'm still trying to grasp the nuances of filter and row contexts.
The products table contains data like...
ProdID.....BaseID....Name...Country
7190...........7190.....xxxx.....US
150207190......7190.....XXXX....Panama
241807190......7190.....xxxx.....Spain
The sales table contains data like...
ProdID......SalesMonth......Units.....USD
7190........July 2010.......4563....$23491.00
150207190...July 2010.......2543....$16235.00
241807190...July 2010.......1263....$8125.00
There is a dates table as well that links the SalesMonth to the usual selection of date display formats. The two tables above are linked via ProdID, though the visuals are sliced by the BaseID. I'd attach a picture, but don't have permissions to do so.
With some more tinkering I found this solution.
Country Rank =
VAR ProdSales = SUM(tblSales[Units])
VAR ProdCountry = SELECTEDVALUE(tblProducts[Country])
VAR tblCountrySales =
SUMMARIZE (
FILTER(
ALLEXCEPT(tblProducts,tblProducts[BaseID]),
tblProducts[Country]=ProdCountry
),
tblProducts[ProdID],
"Total Sales", SUM ( tblSales[Units] )
)
RETURN
IF(ProdSales>0,COUNTROWS(FILTER(tblCountrySales,[Total Sales]>ProdSales))+1,BLANK())