Forum Discussion

Br1-981's avatar
Br1-981
Helper I
2 years ago
Solved

Custom Matrix

Hi, I would build a matrix like this including 2 measures (assume costs and % of each class at category level). Is there any way to build something like this? Consider that categories are dynamic ...
  • giammariam's avatar
    giammariam
    2 years ago

    Br1-981, thanks for the .pbix. I created 2 measures:

     

    _Shares = 
    VAR _selectedSumOfSales = SUMX(
        Sheet1,
        Sheet1[ Sales]
    )
    VAR _selectedProduct = SELECTEDVALUE(Sheet1[Product])
    VAR _totalSalesPerSegment = SUMX(
        FILTER(
            ALLSELECTED(Sheet1),
            Sheet1[Product] = _selectedProduct
        ),
        Sheet1[ Sales]
    )
    RETURN DIVIDE(_selectedSumOfSales, _totalSalesPerSegment)

     

     

     

    _Sales&SharesFormatted = 
    VAR _lineBreak = UNICHAR(10)
    VAR _sales = SUMX(
        Sheet1,
        Sheet1[ Sales]
    )
    
    /*** 
    Dynamic number formatting. Found here:
    https://community.fabric.microsoft.com/t5/Custom-Visuals-Ideas/Auto-Format-Numbers-in-Billions-Millions-Thousands-etc/idi-p/1439322
    ***/
    VAR _safeLog =
        IFERROR ( ABS(INT ( LOG ( ABS ( _sales), 1000 ) )), 0 )
    VAR dp = 1
    
    VAR _salesFormatted = ROUND ( DIVIDE ( _sales, 1000 ^ _safeLog ), dp )
            & SWITCH ( _safelog, 1, "K", 2, "M", 3, "B", 4, "T" )
    /***/
    
    VAR _sharesFormatted = FORMAT([_Shares], "0.00%")
    
    RETURN _salesFormatted&_lineBreak&_sharesFormatted

     


    I then placed [_Sales&SharesFormatted] as the only field in the Values well. 

    You will want to play with the formatting in the [_Sales&SharesFormatted] measure.

    If you need the sales in bold, this can be down using dynamic SVGs. I can help with this if needed. Otherwise, if this is enough to get you going please consider liking this reply and choosing it as the solution. Otherwise, I'm happy to help further.