Forum Discussion

TessSA's avatar
TessSA
Frequent Visitor
1 year ago
Solved

Measure DAX division not working as expected - skipping rows

Hello, I have a table like below (see attached sceenshot):

 

Opportunity NameSKU CategoryTotal Price% Sales on X
ACOM         2.823,93 €2,09%
ACONFIG                           -   €0,00%
AX   134.919,31 € 
ASUP         7.840,00 €5,81%
BACC         4.125,45 € 
BCOM         2.397,67 €0,50%
BCONFIG                           -   €0,00%
BX   482.572,80 € 
BSUP                           -   €0,00%
CACC   107.999,35 € 
CCOM         9.294,00 € 
CFL         3.570,00 €0,94%
CX   380.010,33 € 
CSUP                           -   €0,00%
DCOM      17.200,00 €2,07%
DCONFIG                           -   €0,00%
DX   831.628,76 € 
DSP      44.772,75 €5,38%

 

Where "% Sales on X" is a measure calculated as follow:

 

% Sales on X =
var _category = SELECTEDVALUE('Table'[SKU Category])
var _value = SELECTEDVALUE('Table'[Total Price])
var _total = [Total X Sales]
var _result = IF(_category <> "X", DIVIDE(_value, _total, ""), BLANK())
return _result
 
For some rows, highlighted in red above, the measure doesn't return anything (just blank) although it shoud be returning a % value. This is happening for different SKU categories, where for some Opportunities it is calculated correctly but other ones it comes up empty.
 
Any idea why this coud be happening?
  • TessSA's avatar
    TessSA
    1 year ago

    Thank you, I had to adapt the DAX a bit but I was able to fix it by using SUMX for my value as follows:

     

    % Sales on X =
    var _category = SELECTEDVALUE('Table'[SKU Category])
    var _value = SUMX('Table', 'Table'[Total Price])
    var _total = [Total X Sales]
    var _result = IF(_category <> "X"DIVIDE(_value_total""), BLANK())
    return _result
     
    My "Total Price" column in my data set is alreayd the Qty * Unit Price. 
    My total variable, [Total X Sales] was already being calculated correctly.

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello TessSA ,

    You can try to use a SUMX nested in a CALCULATE in a VAR for your TOTALX measure, ex:

    VAR _category = SELECTEDVALUE('Table'[SKU Category])
    VAR _Total Sales = SUMX('Table',
                                              [Price]  *   [Quantity])
    VAR _Total X = CALCULATE(
                              SUMX('Table',
                                              [Price]  *   [Quantity]),
                               FILTER('Table',
                                       [SKU Category]  = "X"))

    RETURN 
                  IF(
                       CALCULATE(
                             MAX('Table'[SKU Category]) 'Table'[SKU Category] = _category)  <> "X",
                             _Total Sales/_Total X, BLANK())
    )



     

    • TessSA's avatar
      TessSA
      Frequent Visitor

      Thank you, I had to adapt the DAX a bit but I was able to fix it by using SUMX for my value as follows:

       

      % Sales on X =
      var _category = SELECTEDVALUE('Table'[SKU Category])
      var _value = SUMX('Table', 'Table'[Total Price])
      var _total = [Total X Sales]
      var _result = IF(_category <> "X"DIVIDE(_value_total""), BLANK())
      return _result
       
      My "Total Price" column in my data set is alreayd the Qty * Unit Price. 
      My total variable, [Total X Sales] was already being calculated correctly.
  • Hi TessSA 

     

    For each row in your table, this variable should return a non-blank value: var _value = SELECTEDVALUE('Table'[Total Price]). If it returns blank, it could be because _total for those rows return blank. To troubleshoot, return the result of each variable one by one either in the same or separate measures.

     

    • TessSA's avatar
      TessSA
      Frequent Visitor

      Thanks for your guidance. After looking into, it does seem that at the individual row level the measure is calculating correctly but the issues arises for the SKU Category Row Totals when there are multiple rows assigned to one same SKU category, it returns a blank value. I think the issue comes from the fact that the selectedvalue function expects a unique value for the column selected, while in the total I have many of them (under a selected SKU Category there can exist various lines). Maybe I should adapt my measure and use X functions (like sumx) to iterate over each individual row and get the final result needed. I am not sure how to add a X function in my measure, do you have any tips or other ways to solve this issue?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi TessSA ,

     

    May I ask if the [Total X Sales] in your expression refers to another measure? Can you share what it is?

     

    Also, Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

     

     

    Best Regards,

    Clara Gong

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.