Forum Discussion

_Parjam_'s avatar
_Parjam_
Copper Contributor
Jan 07, 2022
Solved

Power Pivot, Measures

Hello, I have a spreadsheet, which includes measures, pivot tables and pivot charts. I would like to be able to save the spreadsheet without any source data. How ever, when I erase the source data the pivot tables and the pivot charts disappear from the spreadsheet, as the measures produce errors due to the data format change which power pivot does from whole number to text value when a source table in not populated. Is there any way to avoid power pivot from changing the data type or any DAX solution to this issue?  

  • _Parjam_ 

    You can't add data directly to data model, thus yes, you need to keep P&L in Totals. When you clean all data data model can't recognize which data types are loaded and by default assumes everything as Text. Thus measure returns an error. Thus PivotTable becomes destroyed and lost the structure.

     

    I'd suggest

    1) Keep dummy table as

    with any date after Feb 1900, product name which definitely won't be repeated in actual data, any other numbers.

    2) Delete P_L Append query and do everything in in one P_L query, in particular

    et
        Source = Table.NestedJoin(
            SALES, {"PRODUCT"},
            COST_TBL, {"PRODUCT"},
            "COST_TBL", JoinKind.LeftOuter),
        PLappend = Excel.CurrentWorkbook(){[Name="P_L"]}[Content],
        PLappendFiltered = Table.SelectRows(
            PLappend,
            each ([#"DATE "] <> null)),
        dummy = Excel.CurrentWorkbook(){[Name="dummy"]}[Content],
    ...

    combine all together, set data types and filter nulls

    ...
        #"Appended Query" = Table.Combine(
            {#"Added Custom1",
             PLappendFiltered,
             dummy}),
        #"Changed Type" = Table.TransformColumnTypes(
            #"Appended Query",
            {
                {"DATE ", type date},
                {"PRODUCT", type text},
                {"UNITS SOLD", Int64.Type},
                {"PRICE", Currency.Type},
                {"COST", Currency.Type},
                {"P&L/UNIT", Currency.Type},
                {"P&L", Currency.Type}}),
        #"Filtered Rows" = Table.SelectRows(
            #"Changed Type",
            each ([#"DATE "] <> null)),
    ...

     3) modify measures as

    COSTS:=CALCULATE(SUM(P_L[UNITS SOLD]), P_L[PRODUCT] <> "no product" )
    SOLD:=CALCULATE(SUM(P_L[PRICE]), P_L[PRODUCT] <> "no product" )
    TOTAL UNITS:=CALCULATE(SUM(P_L[UNITS SOLD]), P_L[PRODUCT] <> "no product" )

    4) disable background refresh for queries to be sure in proper PivotTable refresh

    With that if you delete all data and refresh PivotTable/Chart will be empty but correctly structured

    If add any sales data and refresh

7 Replies

  • Hi
    Are you using Power Query to load the data into Power Pivot?
    When you say you erase the source data what steps are you actually doing? Where is the source data held and how is it getting loaded into Power Pivot?
    • _Parjam_'s avatar
      _Parjam_
      Copper Contributor

      Wyn Hopkins Unfortunately I can not share the spreadsheet here, but I have recreated the same problem in the attached spreadsheets. The main question is whether it is possible to maintain pivot tables and pivot charts intact with all the fields and headers, when the source data in the tables are erased. It seems that the fields disappear due to the error in the measure formulas, the error could be avoided if the data model would not change the data type to text when columns have no data. 

      • I don't understand sorry, if you delete the data nothing will happen, unless you click refresh.
        However when I click refresh it fails as there's an odd relationship with the Calendar.

        Side tip, you don't need CALCULATE in your measures

Resources