Forum Discussion

tannhq's avatar
tannhq
Helper I
4 years ago
Solved

Count rows in table visual with Field Parameters

Hello everyone, 

I have a question.
Before that, I can use the COUNTROWS and SUMMARIZECOLUMNS to caculate the number of rows visible in the visual table.
But now we apply Field parameters, how can we know.

Code to caculate rows before.
No of Raw Table =
COUNTROWS (
SUMMARIZECOLUMNS (
'Product'[Franchise],
'Product'[STMS Product Group],
'Product'[STMS Product Name],
'CustomerType'[CHANNEL (groups)],
'Calendar'[Year-Month],
'Region'[REGION],
'Area'[AreaName],
'Customer'[CustomerName],
'Sales'[InvoiceDate],
'Customer'[Code],
"Value", 'Measure'[Value]
)
)
Thanks,

22 Replies

  • As long as you use a measure to count your rows everything will keep working as before.  If you use a calculated column then that will stop working.

    • tannhq's avatar
      tannhq
      Helper I

      Thanks for your answer.

      Measure above to calcuate no of Visual Table based on the Fixed selected columns, but when we use field parmeters, the seleted columns will be changed and the rows in the Visual Table will be changed as well.

       

      I try with perfomace analyzer and copy the dax code to Dax Studio, there are 2 parts of dax code and don't know how to use it with Field Parameters. 

      • ppdas2112's avatar
        ppdas2112
        Helper I

        lbendlin what should I put inside ALLSELECTED()? If I put the table name, the original table row count is shown, not the dynamic row count based on Field Parameter selection. Pls note that the row count keeps changing based on selection of Fields

    • ppdas2112's avatar
      ppdas2112
      Helper I

       

      lbendlin something has to be specified? I am getting the above error.

      Basically I would need the names of the fields that I have selected using Field Parameter inside ALLSELECTED(). How can I make that dynamic? That will solve the problem

      • lbendlin's avatar
        lbendlin
        Super User

        Please provide some sample data.  Are you using a matrix visual?

  • Ashvini3Jadhav's avatar
    Ashvini3Jadhav
    Frequent Visitor

    Hi tannhqgp10 , algunn14 ,

     

    I am happy to inform that I could implement the solution for deriving countrows in table visual/Card visual with field parameters. It can be used in following cases -
    1. Countrows based on User's selection
    2. Field parameter has columns from multiple tables (More than 1)

     

    If my field parameter(Attribute selection list) has 7 columns,
    1. Fact - V_fct_view (Column1,Column5,Column6,Column7)
    2. V_dim1_view (Column2)
    3. V_dim2_view (Column3,Column4)

    Fact is joined with both dimensions.

     

    Field Parameter -
    Attribute selection list = {
    ("Column1", NAMEOF(V_fct_view[Column1]), 0),
    ("Column2", NAMEOF(V_dim1_view[Column2]), 1),
    ("Column3", NAMEOF(V_dim2_view[Column3]), 2),
    ("Column4", NAMEOF(V_dim2_view[Column4]), 3),
    ("Column5", NAMEOF(V_fct_view[Column5]), 4),
    ("Column6", NAMEOF(V_fct_view[Column6]), 5),
    ("Column7", NAMEOF(V_fct_view[Column7]), 6)}

     

    Formula to get Countrows -
    Countrows_Custom =
    VAR cr = DISTINCT('Attribute selection list'[Attribute selection list Fields])
    var tbl = ADDCOLUMNS(V_fct_view,
    "C1", if(NAMEOF(V_fct_view[Column1]) in cr, V_fct_view[Column1]),
    "C2", if(NAMEOF(V_dim1_view[Column2]) in cr, RELATED(V_dim1_view[Column2])),
    "C3", if(NAMEOF(V_dim2_view[Column3]) in cr, RELATED(V_dim2_view[Column3])),
    "C4", if(NAMEOF(V_dim2_view[Column4]) in cr, RELATED(V_dim2_view[Column4])),
    "C5", if(NAMEOF(V_fct_view[Column5]) in cr, V_fct_view[Column5]),
    "C6", if(NAMEOF(V_fct_view[Column6]) in cr, V_fct_view[Column6]),
    "C7", if(NAMEOF(V_fct_view[Column7]) in cr, V_fct_view[Column7])
    )
    RETURN COUNTROWS( SUMMARIZE(tbl,[C1], [C2], [C3], [C4], [C5], [C6], [C7]))

     

    Note - You need to use Related function with dimension columns. The first parameter of Addcolumns function should be Fact.

     

    Please let me know if you need additional details of the function used in the solution or logic applied to derive the solution.