"aggregations"
4 TopicsMatrix rows not summing properly
I have the measure below that is calculating everything properly on a month by month context. But when I put it in a matrix with the Billing Groups in rows, the Total columns are not summing all the values. I have tried adding DIM_CALENDAR[YYYYMM] to the SUMMARIZECOLUMNS filter, and wrapping the whole thing in another SUMX function using SUMMARIZECOLUMNS( DIM_CALENDAR[YYYYMM] ) for the table context. Neither works right. SUMX( SUMMARIZECOLUMNS( DIM_EMPLOYEE[Billing Group], 'Agreement Additions'[AGR Header RecID] ), VAR DateStart = MIN(DIM_CALENDAR[Date]) VAR DateEnd = MAX(DIM_CALENDAR[Date]) VAR AGR_Header_RecID = 'Agreement Additions'[AGR Header RecID] VAR BillingGroup = DIM_EMPLOYEE[Billing Group] VAR Product_RecID_Filter = SWITCH( TRUE(), BillingGroup = "Group 1", 958, BillingGroup = "Group 2", 956, BillingGroup = "Group 3", 1133, BillingGroup = "Group 4", 869, 0 ) VAR ExtPrice = CALCULATE( FIRSTNONBLANK('Agreement Additions'[Allocation], 1), 'Agreement Additions'[Billing Group RecId] = Product_RecID_Filter, Agreements[AGR Header RecID] = AGR_Header_RecID, Agreements[AGR Type RecID] = 30, Agreements[Date Start] <= DateEnd, (ISBLANK(Agreements[Date End]) || Agreements[Date End] >= DateStart), (ISBLANK('Agreement Additions'[Cancelled Date]) || 'Agreement Additions'[Cancelled Date] >= DateStart) ) RETURN ExtPrice ) For the model, Agreements and Agreement Additions tables are related one to many on the AGR Hearder RecID columns, but the are not related to any of the other tables in the measure.Solved866Views0likes4CommentsHow to do "bitwise or aggregation" on a column? (or how to run aggregates on substrings?)
I would like to understand if and how I could perform a "bitwise or aggregation" on a column, to calculate the bitwise or for all values in a specific column, to be included in a DAX measure. Simplified dataset to explain The (simulated and drastically simplified) source data I have is daily data which consists of the following dimensional attributes date in the form of day of month / month customer category product_group and has many numerical metrics, in this example represented by value_1. In PowerBI I have many measures defined to which sum etc. on the value_xx columns which I can group / display across many of the dimensions. The problem Due to load peformance I want to change the PowerBI dashboard to monthly aggregates, vs. daily data which in 99% of the cases is looked at on a monthly basis only. I can do a lot of aggregations to monthly basis in the SQL load scripts, because the majority of my measures is summing anyhow. However one of the key measures I have is the distinct count of days per month, which nicely calculates in the PowerBI report across all the different dimensions, filters, etc. because I have the individual days as my finest granularity. When I move up to monthly granularity, I will lose the ability to run these distinct days per month counts. Prepare data to monthly aggregate in my source system To overcome this challenge I thought of generating a bit string of length 31 (representing day 1 - 31 in the month) as part of my datapreparations (simple pseudo formula: string(10^(day of month -1)) So: on day 1- bit 1 is set to 1 on day 2, bit 2 is set to 1 ... on day 31, bit 31 is set to 1 an example can be found in the 'day_of_month_bit_position' column in the sample data set below. since this is a string, I can also calculate the decimal reprenstation for this based on bin2dec conversions in my source system. that's what is found in day_of_month_bit_as_decimal. In my source I can also generate the bitwise or aggregates when grouping into my month aggregates, which practically means that for each position in the string the maximum value is taken across all observations I aggregate over. So the monthly aggregate will have 1s on the bits representing the days we had data for. Examle (with week bit string representing mo-sun, because 31 is a lot of 1s and zeroes in an example): aggregate 1, data on mon, wed and fri --> 1010100 (3 unique days) aggregate 2, data on wed, fri, sat and sun --> 0010111 (4 unique days) the bitwise or of this results in 1010111 (5 unique days, mon, wed, fri, sat, sun) How to do this same aggregation in PowerBI using a measure? I want to be able to do this same 'bitwise or aggregation' in PowerBI to count the unique days in my current context, to do so I thought of the following steps generate the 'bitwise or aggregated' bit string sum all 1s / bit_count the bit string return this value as the unique days Struggling to get it working I have been banging my head against the wall now for some hours to get anywhere with this. Constantly ending up in dead ends 😞 . To summarize (in the example below): when I aggregate month 2 for customer_1 the bitwise or aggregate should result in 0000100100000100000000000000000 summing over/bitcounting this bit string results in 3 unique days. Note: I know this is still daily data, I on purpose provided this example instead of the monthly_pre_aggregates which I can create from my source, because validation of the calculation is still possible, since day_of_month is present.1.5KViews0likes8CommentsProducts Assortment with sales>0 count in the last 3 months
My data contains a monthly data of products sales. I wish to create a measure that counts the number of products with sales above zero in the last 3 month. I already created successfully a measure that sums up the sales in the last 3 months (by using DATESINPERIOD). i tried this formula: Assortment = CALCULATE(count(Sales[product]),filter(sales,[SalesLast3Months]>0),filter(Sales,Sales[Date]=max(Sales[Date]))) but all i get is indeed the number of products with sales>0 but only as of the LAST month and not three aggregated. appreciate your help in advance!2.2KViews0likes5Comments